//! private void RandomizeWeights() { var rnd = new Random(); //distribute -0.5 to 0.5. WeightHiddenOutput.Initialize(() => rnd.NextDouble() - 0.5); WeightInputHidden.Initialize(() => rnd.NextDouble() - 0.5); }
public void Train(double[] inputs, double[] targets) { var inputSignals = ConvertToMatrix(inputs); var targetSignals = ConvertToMatrix(targets); var hiddenOutputs = Sigmoid(WeightInputHidden * inputSignals); var finalOutputs = Sigmoid(WeightHiddenOutput * hiddenOutputs); var outputErrors = targetSignals - finalOutputs; var hiddenErrors = WeightHiddenOutput.Transpose() * outputErrors; WeightHiddenOutput += LearningRate * outputErrors * finalOutputs * (1.0 - finalOutputs) * hiddenOutputs.Transpose(); WeightInputHidden += LearningRate * hiddenErrors * hiddenOutputs * (1.0 - hiddenOutputs) * inputSignals.Transpose(); }