コード例 #1
0
        void SearchSolution()
        {
            // create network
            DistanceNetwork network = new DistanceNetwork(2, neurons);

            // set random generators range
            foreach (var neuron in network.Layers.SelectMany(layer => layer?.Neurons).Where(neuron => neuron != null))
            {
                neuron.RandGenerator = new UniformContinuousDistribution(new Range(0, 1000));
            }


            // create learning algorithm
            ElasticNetworkLearning trainer = new ElasticNetworkLearning(network);

            double fixedLearningRate    = learningRate / 20;
            double driftingLearningRate = fixedLearningRate * 19;

            double[,] path = new double[neurons + 1, 2];
            double[] input = new double[2];
            int      i     = 0;

            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);

                i++;

                SetText(currentIterationBox, i.ToString());

                if (i >= iterations)
                {
                    break;
                }
            }

            // enable settings controls
            EnableControls(true);
        }
コード例 #2
0
        // Worker thread
        void SearchSolution()
        {
            // set random generators range
            Neuron.RandRange = new Range(0, 1000);

            // create network
            var network = new DistanceNetwork(2, neurons);

            // create learning algorithm
            var trainer = new ElasticNetworkLearning(network);

            var fixedLearningRate    = learningRate / 20;
            var driftingLearningRate = fixedLearningRate * 19;

            // path
            var path = new double[neurons + 1, 2];

            // input
            var input = new double[2];

            // iterations
            var 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
                var 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 (var 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);
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: antoniogjose/GreedyAlgorithm
        //http://www.aforgenet.com/framework/docs/

        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];

                chart1.UpdateDataSeries("Caminho", path);
                i++;


                SetText(i.ToString());

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