+/GENN

genetically evolving neural networks

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

Joseph RyanStill brokeneb6e103

v0.2
1.2 KiB68 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
13class Species {
14public:
15    std::vector<Genome *> genomes;
16    int staleness = 0;
17    double maxFitness = 0;
18    static bool compare(Species a, Species b) { return (a.maxFitness > b.maxFitness); }
19};
20
21class NEAT {
22private:
23    std::vector<std::array<int, 2>> innovation;
24
25    std::vector<Species> species;
26
27    int population, staleThreshold, generation, maxSpecies;
28
29    double c1, c2, c3, distanceThreshold;
30
31    std::ofstream f;
32
33public:
34    NEAT(int inputs, int outputs);
35
36    ~NEAT();
37
38    void config(); //for setting constants like gen size and mutation rates
39
40    void classify();
41
42    void cull();
43
44    void status();
45
46    void adjustFitness();
47
48    void log();
49
50    double distance(Genome *, Genome *);
51
52    //staleness hurts chances unless at the top
53    Genome *mate(Genome *, Genome *);
54
55    bool innovationExists(int a, int b);
56
57    int newInnovation(int a, int b);
58
59    void mutate(Genome &);
60
61    std::vector<Genome *> pool;
62
63    void repopulate();
64
65    void nextGen();
66};
67
68#endif //GENN_NETWORK_H