예제 #1
0
        public void SetNeuralNetwork(IFunctionApproximator fapp)
        {
            FeedForwardNeuralNetwork ffnn = (FeedForwardNeuralNetwork)fapp;

            this.hiddenLayer       = ffnn.GetHiddenLayer();
            this.outputLayer       = ffnn.GetOutputLayer();
            this.hiddenSensitivity = new LayerSensitivity(hiddenLayer);
            this.outputSensitivity = new LayerSensitivity(outputLayer);
        }
예제 #2
0
        public static Matrix CalculateWeightUpdates(
            LayerSensitivity layerSensitivity,
            Vector previousLayerActivationOrInput, double alpha)
        {
            Layer  layer = layerSensitivity.GetLayer();
            Matrix activationTranspose = previousLayerActivationOrInput.Transpose();
            Matrix weightUpdateMatrix  = layerSensitivity.GetSensitivityMatrix()
                                         .Times(activationTranspose).Times(alpha).Times(-1.0);

            layer.AcceptNewWeightUpdate(weightUpdateMatrix.Copy());
            return(weightUpdateMatrix);
        }
예제 #3
0
        public Matrix CalculateWeightUpdates(LayerSensitivity layerSensitivity,
                                             Vector previousLayerActivationOrInput, double alpha, double momentum)
        {
            Layer  layer = layerSensitivity.GetLayer();
            Matrix activationTranspose = previousLayerActivationOrInput.Transpose();
            Matrix momentumLessUpdate  = layerSensitivity.GetSensitivityMatrix()
                                         .Times(activationTranspose).Times(alpha).Times(-1.0);
            Matrix updateWithMomentum = layer.GetLastWeightUpdateMatrix().Times(
                momentum).Plus(momentumLessUpdate.Times(1.0 - momentum));

            layer.AcceptNewWeightUpdate(updateWithMomentum.Copy());
            return(updateWithMomentum);
        }
예제 #4
0
        public Matrix SensitivityMatrixFromSucceedingLayer(
            LayerSensitivity nextLayerSensitivity)
        {
            Layer  nextLayer        = nextLayerSensitivity.GetLayer();
            Matrix derivativeMatrix = this.CreateDerivativeMatrix(layer
                                                                  .GetLastInducedField());
            Matrix weightTranspose             = nextLayer.GetWeightMatrix().Transpose();
            Matrix calculatedSensitivityMatrix = derivativeMatrix.Times(
                weightTranspose).Times(nextLayerSensitivity.GetSensitivityMatrix());

            sensitivityMatrix = calculatedSensitivityMatrix.Copy();
            return(sensitivityMatrix);
        }
예제 #5
0
        public static Vector CalculateBiasUpdates(
            LayerSensitivity layerSensitivity, double alpha)
        {
            Layer  layer            = layerSensitivity.GetLayer();
            Matrix biasUpdateMatrix = layerSensitivity.GetSensitivityMatrix()
                                      .Times(alpha).Times(-1.0);

            Vector result = new Vector(biasUpdateMatrix.GetRowDimension());

            for (int i = 0; i < biasUpdateMatrix.GetRowDimension(); i++)
            {
                result.SetValue(i, biasUpdateMatrix.Get(i, 0));
            }
            layer.AcceptNewBiasUpdate(result.CopyVector());
            return(result);
        }
예제 #6
0
        public Vector CalculateBiasUpdates(LayerSensitivity layerSensitivity,
                                           double alpha, double mom)
        {
            Layer  layer = layerSensitivity.GetLayer();
            Matrix biasUpdateMatrixWithoutMomentum = layerSensitivity
                                                     .GetSensitivityMatrix().Times(alpha).Times(-1.0);

            Matrix biasUpdateMatrixWithMomentum = layer.GetLastBiasUpdateVector()
                                                  .Times(mom).Plus(biasUpdateMatrixWithoutMomentum.Times(1.0 - mom));
            Vector result = new Vector(biasUpdateMatrixWithMomentum
                                       .GetRowDimension());

            for (int i = 0; i < biasUpdateMatrixWithMomentum.GetRowDimension(); i++)
            {
                result.SetValue(i, biasUpdateMatrixWithMomentum.Get(i, 0));
            }
            layer.AcceptNewBiasUpdate(result.CopyVector());
            return(result);
        }