Пример #1
0
        //
        // Find fitness of this particle for all training data
        //  - This is the summed squared error
        public double GetFitness(double[][] inputArray, double[][] outputArray)
        {
            double error = 0;   // Initialize error to 0

            // Get error
            int row = 0;

            foreach (double[] line in inputArray)
            {
                double[] output = currNetwork.Think(line);
                int      col    = 0;
                foreach (double val in output)
                {
                    error += Math.Abs((val - outputArray[row][col]) * (val - outputArray[row][col]));
                    col++;
                }
                row++;
            }
            ParticleFitness = error;

            // Check for personal best
            if (ParticleFitness < PersonalBest)
            {
                PersonalBest = ParticleFitness;
                bestNetwork  = currNetwork.SetWeights();
            }

            return(ParticleFitness);
        }
Пример #2
0
        //
        // Get MSE of global best network to test data
        public double BestTestFitness()
        {
            double error = 0;   // Initialize error to 0

            // Get error
            int row = 0;

            foreach (double[] line in TestInputs)
            {
                double[] output = bestNetwork.Think(line);
                int      col    = 0;
                foreach (double val in output)
                {
                    error += Math.Abs((val - TestOutputs[row][col]) * (val - TestOutputs[row][col]));
                    col++;
                }
                row++;
            }
            return(error / TestInputs.Length);
        }