+/GENN

genetically evolving neural networks

git clone https://git.julia.blue/+/GENN

Joseph RyanRestructure file system add graphics libcc48e92

imdone-todo-updates
927 B34 linesraw
1#include "Xor.h"
2
3Xor::Xor() {
4    controller = new NEAT(3, 1);
5}
6
7void Xor::evaluate(Genome &g) {
8    Network n(g);
9    double error = 0.0;
10    for (int i = 0; i < 4; ++i) {
11        double a[1];
12        n.reset();
13        for (int j = 0; j < 5; ++j) {
14            n.propagate(testData[i], a);
15        }
16        error += std::abs(answers[i] - a[0]);
17    }
18    g.fitness = std::max(0., 4 - error);
19}
20
21void Xor::view(Network n) {
22    double error = 0.0;
23    for (int i = 0; i < 4; ++i) {
24        double a[1];
25        n.reset();
26        for (int j = 0; j < 5; ++j) {
27            n.propagate(testData[i], a);
28        }
29        error += std::abs(answers[i] - a[0]);
30        std::cout << "Input: " << testData[i][0] << ", " << testData[i][1] << ". Answer: " << a[0] << ". Expected: "
31                  << answers[i] << " Error: " << std::abs(a[0] - answers[i]) << std::endl;
32    }
33    std::cout << "Error: " << error << std::endl;
34}