pulsatrix
Loading...
Searching...
No Matches
neat_xor_fitness.hpp
Go to the documentation of this file.
1
9#pragma once
10
11#include <array>
12#include <vector>
13
16
17namespace pulsatrix {
18
27inline double XORFitness(const NEATGenome& genome) {
28 static const std::array<std::array<double, 2>, 4> kInputs{
29 {{0.0, 0.0}, {0.0, 1.0}, {1.0, 0.0}, {1.0, 1.0}}};
30 static const std::array<double, 4> kExpected{0.0, 1.0, 1.0, 0.0};
31
32 double sum_squared_error = 0.0;
33 for (size_t i = 0; i < kInputs.size(); ++i) {
34 std::vector<double> inputs(kInputs[i].begin(), kInputs[i].end());
35 double actual = EvaluateNEATPhenotype(genome, inputs)[0];
36 double error = kExpected[i] - actual;
37 sum_squared_error += error * error;
38 }
39 return 4.0 - sum_squared_error;
40}
41
42} // namespace pulsatrix
A NEAT genome: its node and connection genes, growable via structural mutation.
Definition neat_genome.hpp:94
Definition acquisition_functions.hpp:16
std::vector< double > EvaluateNEATPhenotype(const NEATGenome &genome, const std::vector< double > &inputs)
Evaluates genome's phenotype forward pass on inputs (one value per Input node, ordered by ascending n...
Definition neat_phenotype.hpp:42
double XORFitness(const NEATGenome &genome)
Evaluates genome's phenotype on all four XOR patterns ((0,0)->0, (0,1)->1, (1,0)->1,...
Definition neat_xor_fitness.hpp:27
NEAT genome (Stanley & Miikkulainen, "Evolving Neural Networks through Augmenting Topologies,...
Decodes a NEATGenome into an evaluable phenotype: a forward pass over the genome's own irregular conn...