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); }
private float ComputeFitness(NeuralGenome genome) { genome.NetworkOperationBaker.BakeNetwork(genome); var fitness = 0d; for (var i = 0; i < 2; i++) { for (var j = 0; j < 2; j++) { genome.FeedNeuralNetwork(new float[] { i, j }); var output = genome.Outputs.Select(x => x.Value).First(); var targetValue = i ^ j; var delta = Math.Abs(targetValue - output); var gradient = (i == j && i == 1) ? 5 : 1; fitness -= delta * gradient; } } if (fitness >= -0.01f) { targetReached = true; } return((float)fitness); }
private void MoveFromNetwork() { if (neuralGenome == null) { return; } neuralGenome.FeedNeuralNetwork(GenerateNetworkInputs()); var outputs = neuralGenome.Outputs.Select(x => x.Value).ToArray(); cartRb.AddForce(Vector2.right * outputs[0] * xVelocity * Time.fixedDeltaTime); }
private float ComputeFitness(NeuralGenome genome) { var fitness = 0d; for (var i = 0; i < Math.Pow(2, inputs) - 1; i++) { genome.NetworkOperationBaker.BakeNetwork(genome); genome.FeedNeuralNetwork(GetBits(i).Select(x => (float)x).ToArray()); var expectedOutput = GetBits(i + 1); fitness -= genome.Outputs.Select(x => x.Value) .Zip(expectedOutput, (o, e) => Math.Abs(o - e)) .Sum(); } return((float)fitness); }
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); }