Пример #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
 //
 // Constructor
 public Particle(int[] LayerInfo, int[] inputStats, int[] outputStats, bool[] inUseOpponent, bool[] inUseOffense, Random random)
 {
     currNetwork = new Neural_Network(LayerInfo, inputStats, outputStats, inUseOpponent, inUseOffense, random);
     bestNetwork = currNetwork.SetWeights();
     stepNetwork = new Neural_Network(LayerInfo, inputStats, outputStats, inUseOpponent, inUseOffense, 0);
 }