Encog.Util.Concurrency.DetermineWorkload.CalculateWorkers C# (CSharp) Méthode

CalculateWorkers() public méthode

Calculate the high and low ranges for each worker.
public CalculateWorkers ( ) : IList
Résultat IList
        public IList<IntRange> CalculateWorkers()
        {
            IList<IntRange> result = new List<IntRange>();
            int sizePerThread = _workloadSize/_threadCount;

            // create the workers
            for (int i = 0; i < _threadCount; i++)
            {
                int low = i*sizePerThread;
                int high;

                // if this is the last record, then high to be the last item
                // in the training set.
                if (i == (_threadCount - 1))
                {
                    high = _workloadSize - 1;
                }
                else
                {
                    high = ((i + 1)*sizePerThread) - 1;
                }

                result.Add(new IntRange(high, low));
            }

            return result;
        }
    }

Usage Example

        /// <inheritdoc />
        public override void Init(BasicNetwork theNetwork, IMLDataSet theTraining)
        {
            base.Init(theNetwork, theTraining);
            int weightCount = theNetwork.Structure.Flat.Weights.Length;

            _training = theTraining;
            _network = theNetwork;

            _hessianMatrix = new Matrix(weightCount, weightCount);
            _hessian = _hessianMatrix.Data;

            // create worker(s)
            var determine = new DetermineWorkload(
                ThreadCount, _training.Count);

            _workers = new ChainRuleWorker[determine.ThreadCount];

            int index = 0;

            // handle CPU
            foreach (IntRange r in determine.CalculateWorkers())
            {
                _workers[index++] = new ChainRuleWorker((FlatNetwork) _flat.Clone(),
                    _training.OpenAdditional(), r.Low,
                    r.High);
            }
        }
All Usage Examples Of Encog.Util.Concurrency.DetermineWorkload::CalculateWorkers