Used by several Encog training methods to break up a workload. Can also be used to determine the number of threads to use. If zero threads are specified, Encog will query the processor count and determine the best number of threads to use.
        /// <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);
            }
        }
Exemple #2
0
 private void xd586e0c16bdae7fc()
 {
     IActivationFunction function;
     DetermineWorkload workload;
     int num2;
     this._x0ba854627e1326f9 = new double[this._x87a7fc6a72741c2e.ActivationFunctions.Length];
     if (!this.FixFlatSpot)
     {
         EngineArray.Fill(this._x0ba854627e1326f9, (double) 0.0);
         goto Label_0045;
     }
     int index = 0;
     if ((((uint) num2) - ((uint) num2)) >= 0)
     {
         goto Label_012E;
     }
     goto Label_014D;
     Label_001D:
     this.InitOthers();
     if (8 != 0)
     {
         return;
     }
     Label_0045:
     workload = new DetermineWorkload(this._xc2715388adc0d1f8, (int) this._x9d091b0a73271a88.Count);
     this._xb542b50e13b3ecac = new GradientWorker[workload.ThreadCount];
     num2 = 0;
     foreach (IntRange range in workload.CalculateWorkers())
     {
         this._xb542b50e13b3ecac[num2++] = new GradientWorker((FlatNetwork) this._x87a7fc6a72741c2e.Clone(), this, this._x9d091b0a73271a88.OpenAdditional(), range.Low, range.High, this._x0ba854627e1326f9, this.ErrorFunction);
     }
     goto Label_001D;
     if ((((uint) index) + ((uint) index)) <= uint.MaxValue)
     {
         goto Label_001D;
     }
     Label_0101:
     this._x0ba854627e1326f9[index] = 0.0;
     if ((((uint) index) - ((uint) num2)) < 0)
     {
         if ((((uint) num2) + ((uint) index)) > uint.MaxValue)
         {
             goto Label_014D;
         }
         goto Label_0101;
     }
     Label_012A:
     index++;
     Label_012E:
     if (index < this._x87a7fc6a72741c2e.ActivationFunctions.Length)
     {
         function = this._x87a7fc6a72741c2e.ActivationFunctions[index];
     }
     else
     {
         goto Label_0045;
     }
     Label_014D:
     if (function is ActivationSigmoid)
     {
         this._x0ba854627e1326f9[index] = 0.1;
         goto Label_012A;
     }
     goto Label_0101;
 }
        /// <summary>
        /// Init the process.
        /// </summary>
        ///
        private void Init()
        {
            // fix flat spot, if needed
            _flatSpot = new double[_flat.ActivationFunctions.Length];

            if (FixFlatSpot)
            {
                for (int i = 0; i < _flat.ActivationFunctions.Length; i++)
                {
                    IActivationFunction af = _flat.ActivationFunctions[i];
                    if( af is ActivationSigmoid )
                    {
                        _flatSpot[i] = 0.1;
                    }
                    else
                    {
                        _flatSpot[i] = 0.0;
                    }
                }
            }
            else
            {
                EngineArray.Fill(_flatSpot, 0.0);
            }

            var determine = new DetermineWorkload(
                _numThreads, (int)_indexable.Count);

            _workers = new GradientWorker[determine.ThreadCount];

            int index = 0;

            // handle CPU
            foreach (IntRange r in determine.CalculateWorkers())
            {
                _workers[index++] = new GradientWorker(((FlatNetwork)_network.Flat.Clone()),
                                                         this, _indexable.OpenAdditional(), r.Low,
                                                         r.High, _flatSpot, ErrorFunction);
            }

            InitOthers();
        }