This class implements elastic network's learning algorithm and allows to train Distance Networks.
// Worker thread void SearchSolution() { // set random generators range Neuron.RandRange = new DoubleRange(0, 1000); // create network DistanceNetwork network = new DistanceNetwork(2, neurons); // create learning algorithm ElasticNetworkLearning trainer = new ElasticNetworkLearning(network); double fixedLearningRate = learningRate / 20; double driftingLearningRate = fixedLearningRate * 19; // path double[,] path = new double[neurons + 1, 2]; // input double[] input = new double[2]; // iterations int i = 0; // loop while (!needToStop) { // update learning speed & radius trainer.LearningRate = driftingLearningRate * (iterations - i) / iterations + fixedLearningRate; trainer.LearningRadius = learningRadius * (iterations - i) / iterations; // set network input int currentCity = rand.Next(citiesCount); input[0] = map[currentCity, 0]; input[1] = map[currentCity, 1]; // run one training iteration trainer.Run(input); // show current path for (int j = 0; j < neurons; j++) { path[j, 0] = network[0][j][0]; path[j, 1] = network[0][j][1]; } path[neurons, 0] = network[0][0][0]; path[neurons, 1] = network[0][0][1]; chart.UpdateDataSeries("path", path); // increase current iteration i++; // set current iteration's info UpdateTextbox(currentIterationBox, i.ToString()); //currentIterationBox.Text = i.ToString(); // stop ? if (i >= iterations) break; } // enable settings controls EnableControls(true); }