示例#1
0
        void backwardTrain(CostLayer costLayer, double learnRate)
        {
            var gradients = costLayer.backward(currentAnnOutput);

            for (int i = layers.Length - 1; i > 0; i--)
            {
                layers[i].backwardLearn(layerInputs[i], gradients, learnRate);
                gradients = layers[i].backward(layerInputs[i], gradients);
            }
            layers[0].backwardLearn(layerInputs[0], gradients, learnRate);
        }
示例#2
0
 void forward(MatrixD inputs, CostLayer costLayer)
 {
     layerInputs[0] = inputs;
     for (int i = 1; i < this.layers.Length; i++)
     {
         layerInputs[i] = this.layers[i - 1].forward(layerInputs[i - 1]);
     }
     this.currentAnnOutput = this.layers.Last().forward(layerInputs.Last());
     if (preCost == null)
     {
         preCost = costLayer.forward(this.currentAnnOutput);
     }
     else
     {
         postCost = costLayer.forward(this.currentAnnOutput);
     }
     //var m = annOutput.ToRowArrays();
 }
示例#3
0
        public void next(double learnRate, int countEntries)
        {
            preCost = postCost = null;
            var randomEntriesIdx = GlobalRandom.NextIntArr(countEntries, 0, annInputs.RowCount - 1);

            this.currentInput          = annInputs.lines(randomEntriesIdx);
            this.currentExpectedOutput = annExpectedOutputs.lines(randomEntriesIdx);

            var costLayer = new CostLayer(currentExpectedOutput);

            forward(currentInput, costLayer);
            backwardTrain(costLayer, learnRate / countEntries);

            /* * /
             * var mO = annOutput.ToRowArrays();
             * var mEO = currentExpectedOutput.ToRowArrays();
             *
             * var mOidx = annOutput.maxIdxEachRow();
             * var mEOidx = currentExpectedOutput.maxIdxEachRow();
             * //*/
        }