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