예제 #1
0
        private void UpdateWeightsIndividual(ref Matrix<double> localHL, ref Matrix<double> localOL, Vector<double> sample, Vector<double> target)
        {
            var hlOut = Sigmoid(localHL.LeftMultiply(sample));

            hlOut = Prepend(1, hlOut);

            var v = Sigmoid(localOL.LeftMultiply(hlOut));

            var deltaOL = v.Subtract(target).PointwiseMultiply(v).PointwiseMultiply(OneMinusV(v));

            var deltaHL = localOL.Transpose().LeftMultiply(deltaOL).PointwiseMultiply(hlOut).PointwiseMultiply(OneMinusV(hlOut));

            var tmp = deltaOL.Multiply(LearningRate).ToColumnMatrix();

            localOL = localOL.Subtract(tmp.Multiply(hlOut.ToRowMatrix()).Transpose());

            tmp = deltaHL.SubVector(1, deltaHL.Count - 1).ToColumnMatrix();
            tmp = tmp.Multiply(LearningRate);

            localHL = localHL.Subtract(tmp.Multiply(sample.ToRowMatrix()).Transpose());
        }