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
Example #1
0
        // Worker thread
        void SearchSolution()
        {
            // create network
            DistanceNetwork network = new DistanceNetwork(2, neurons);

            // set random generators range
            foreach (var layer in network.Layers)
                foreach (var neuron in layer.Neurons)
                    neuron.RandGenerator = new UniformContinuousDistribution(new Range(0, 1000));


            // 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.Layers[0].Neurons[j].Weights[0];
                    path[j, 1] = network.Layers[0].Neurons[j].Weights[1];
                }
                path[neurons, 0] = network.Layers[0].Neurons[0].Weights[0];
                path[neurons, 1] = network.Layers[0].Neurons[0].Weights[1];

                chart.UpdateDataSeries("path", path);

                // increase current iteration
                i++;

                // set current iteration's info
                SetText(currentIterationBox, i.ToString());

                // stop ?
                if (i >= iterations)
                    break;
            }

            // enable settings controls
            EnableControls(true);
        }