예제 #1
0
 private float FeedRNNPair(NeuralGenome genome, int[] values)
 {
     genome.ResetNeuronsValues();
     genome.FeedNeuralNetwork(new float[] { values[0] });
     genome.FeedNeuralNetwork(new float[] { values[1] });
     return(genome.Outputs.First().Value);
 }
예제 #2
0
        private float ComputeFitness(NeuralGenome genome)
        {
            genome.NetworkOperationBaker.BakeNetwork(genome);
            var fitness = 0d;

            // Continuous input.
            foreach (var dataset in datasets)
            {
                genome.ResetNeuronsValues();

                int expectedResult = 0;
                foreach (var input in dataset)
                {
                    expectedResult ^= input;
                    genome.FeedNeuralNetwork(new float[] { input });

                    var delta = Math.Abs(expectedResult - genome.Outputs[0].Value);
                    fitness -= delta;
                }
            }

            // Pair input
            //foreach (var pair in samplePairs)
            //{
            //	var output = FeedRNNPair(genome, pair);
            //	var expectedResult = pair[0] ^ pair[1];

            //	var delta = Math.Abs(expectedResult - output);
            //             fitness -= delta;
            //}

            if (fitness >= -1f)
            {
                targetReached = true;
            }

            return((float)fitness);
        }