public void Learn() { List <int> usedInputs = new List <int>(); List <double> currentOutputs = new List <double>(); int era = 0; do { usedInputs.Clear(); currentOutputs.Clear(); for (int i = 0; i < networkData.Inputs.Count; i++) { int currentInput; do { currentInput = RandomHelper.GetRandomInRange(0, networkData.Inputs.Count); } while (usedInputs.Contains(currentInput)); usedInputs.Add(currentInput); int k = 0; foreach (Neuron neuron in layers.getInputLayer().getNeurons()) { neuron.setOutput(networkData.Inputs[currentInput][k++]); } sumWeightsAndActivate(); calculateSignalErrors(networkData.ExpectedOutputs[currentInput]); updateWeights(); foreach (Neuron neuron in layers.getOutputLayer().getNeurons()) { currentOutputs.Add(neuron.getOutput()); } networkData.ActualOutputs.Add(currentInput, currentOutputs); } updateOverallError(); SingleEraEnded?.Invoke(new SingleEraData() { CurrentEra = era, OverallError = networkData.OverallError, LearnProgress = (era + 1d) / networkConfiguration.MaxEras, PercentOfError = (networkConfiguration.MinError / networkData.OverallError * 100) }); era++; } while (era < networkConfiguration.MaxEras && networkData.OverallError > networkConfiguration.MinError); }
public void Learn() { int era = 0; Random r = new Random(); do { foreach (int currentInput in Enumerable.Range(0, networkData.Inputs.Count).OrderBy(x => r.Next())) { int k = 0; foreach (Neuron neuron in layers.getInputLayer().getNeurons()) { neuron.setOutput(networkData.Inputs[currentInput][k++]); } sumWeightsAndActivate(); calculateSignalErrors(networkData.ExpectedOutputs[currentInput]); updateWeights(); List <double> currentOutputs = new List <double>(); foreach (Neuron neuron in layers.getOutputLayer().getNeurons()) { currentOutputs.Add(neuron.getOutput()); } networkData.ActualOutputs[currentInput] = new List <double>(currentOutputs); } updateOverallError(); SingleEraEnded?.Invoke(new SingleEraData() { CurrentEra = era, OverallError = networkData.OverallError, LearnProgress = (era + 1d) / networkConfiguration.MaxEras, PercentOfError = (networkConfiguration.MinError / networkData.OverallError * 100) }); era++; } while (era < networkConfiguration.MaxEras && networkData.OverallError > networkConfiguration.MinError); }