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); }
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); }
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); }
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); }
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); }
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); }