Run() public method

Runs learning iteration.

The method runs one learning iterations - finds winner neuron (the neuron which has weights with values closest to the specified input vector) and updates its weight (as well as weights of neighbor neurons) in the way to decrease difference with the specified input vector.

public Run ( double input ) : double
input double Input vector.
return double
Ejemplo n.º 1
0
        // 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);
        }