Пример #1
0
        private void neuralNetwork_Finished(object sender, AlgorithmFinishedEventArgs e)
        {
            var classifiers = new List <Double[, ]>();

            foreach (var neuron in e.Neurons)
            {
                double k = (neuron.Weights[1] != 0) ? (-neuron.Weights[0] / neuron.Weights[1]) : 0;
                double b = (neuron.Weights[1] != 0) ? (-((ActivationNeuron)neuron).Threshold / neuron.Weights[1]) : 0;
                double[,] classifier = new double[2, 2]
                {
                    { (float)m_minX, (float)m_minX * k + b },
                    { (float)m_maxX, (float)m_maxX * k + b }
                };
                classifiers.Add(classifier);
            }

            var bestCM = e.Matrix;

            if (MostAccurateNN == null || bestCM.Accuracy > MostAccurateNN.Item2.Accuracy)
            {
                MostAccurateNN = Tuple.Create(classifiers, bestCM);
            }

            m_view.ChartUpdate("nnChart", "classifier1", MostAccurateNN.Item1);
        }
Пример #2
0
        private void perceptron_Finished(object sender, AlgorithmFinishedEventArgs e)
        {
            var neuron = e.Neurons.First();
            // Calculate the coordinates of the classifier
            double k = (neuron.Weights[1] != 0) ? (-neuron.Weights[0] / neuron.Weights[1]) : 0;
            double b = (neuron.Weights[1] != 0) ? (-((ActivationNeuron)neuron).Threshold / neuron.Weights[1]) : 0;

            // Create the line and feed it to the data series
            double[,] classifier = new double[2, 2]
            {
                { (float)m_minX, (float)m_minX * k + b },
                { (float)m_maxX, (float)m_maxX * k + b }
            };

            var cmatrix = e.Matrix;

            //Update the most accurate classification
            if (MostAccuratePerceptron == null || cmatrix.Accuracy > MostAccuratePerceptron.Item2.Accuracy)
            {
                MostAccuratePerceptron = Tuple.Create(classifier, cmatrix);
            }

            m_view.ChartUpdate("perceChart", "classifier", MostAccuratePerceptron.Item1);
        }
Пример #3
0
 /// <summary>
 /// This function is executed when the algorithm in <see cref="GeneticAlgorithmManager"/> is finished.
 /// </summary>
 /// <param name="sender">The sender object.</param>
 /// <param name="e">Object containing the network trained by the algorithm.</param>
 private void GeneticAlgorithm_AlgorithmFinished(object sender, AlgorithmFinishedEventArgs e)
 {
     SaveNeuralNetworkToFile(e.BestChromosome);
     Debug.Log("Algorithm is finished.");
 }