-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetwork.h
74 lines (61 loc) · 1.41 KB
/
Network.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#ifndef _NETWORK_H
// Build Settings
#define _NETWORK_ID
#define _NETWORK_LOG
#ifdef _WIN32
#define _V(T) std::vector<T>
#define _V2(T) std::vector<std::vector<T>>
#define _V3(T) std::vector<std::vector<std::vector<T>>>
#else
#define _V(T) std::vector<T>
#define _V2(T) std::vector<std::vector<T> >
#define _V3(T) std::vector<std::vector<std::vector<T> > >
#endif
#define Random(LO, HI) (LO + (float)(rand()) / ((float)(RAND_MAX/(HI - LO))))
#ifdef _NETWORK_ID
namespace _nid {
inline int CurrentId = 1;
}
#endif
#ifdef _NETWORK_LOG
#define _L(D, N) std::cout << D << (N ? "\n" : "")
#else
#define _L(D, N)
#endif
class NeuralNetwork {
private:
_V(int) Layers;
_V2(float) Neurons;
_V2(float) Biases;
_V3(float) Weights;
public:
#ifdef _WIN32
enum class ComparisonResults {
#else
enum ComparisonResults {
#endif
Worse,
Better,
Equal
};
#ifdef _NETWORK_ID
int Id;
#endif
float Fitness;
void CreateNeurons();
void CreateBiases();
void CreateWeights();
_V(float) Forward(_V(float) Input);
void Mutate(float Chance, float Value);
void CloneFrom(NeuralNetwork Other);
ComparisonResults CompareTo(NeuralNetwork Other);
bool Save(std::string Path);
bool Load(std::string Path);
NeuralNetwork(_V(int) NewLayers, bool CreateID = true);
};
#define _NETWORK_H
#endif