+/GENN

genetically evolving neural networks

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

Joseph RyanRestructure file system add graphics libcc48e92

imdone-todo-updates
1.1 KiB67 linesraw
1#ifndef GENN_NEAT_H
2#define GENN_NEAT_H
3
4#include "Genome.h"
5#include <time.h>
6#include <cstdlib>
7#include <array>
8#include <algorithm>
9#include <fstream>
10#include <iostream>
11
12
13struct Species {
14    std::vector<Genome *> genomes;
15    int staleness = 0;
16    double maxFitness = 0;
17
18    static bool compare(const Species &a, const Species &b) { return a.genomes[0]->fitness > b.genomes[0]->fitness; }
19};
20
21class NEAT {
22private:
23    double m[7];
24
25    std::vector<std::array<int, 2>> innovation;
26
27    std::vector<Species> species;
28
29    int population, staleThreshold, generation, maxSpecies;
30
31    double c1, c2, c3, distanceThreshold, maxFitness;
32
33    std::ofstream f;
34
35    void adjustFitness();
36
37    void log();
38
39    void status();
40
41    void cull();
42
43    void repopulate();
44
45    void classify();
46
47    double distance(Genome, Genome);
48
49    Genome mate(Genome *, Genome *);
50
51    void mutate(Genome &);
52
53    int newInnovation(int a, int b);
54
55    int findInnovation(int a, int b);
56
57    void labelInnovations(Genome &);
58
59public:
60    NEAT(int inputs, int outputs);
61
62    void nextGen();
63
64    std::vector<Genome> pool;
65};
66
67#endif //GENN_NEAT_H