-
Notifications
You must be signed in to change notification settings - Fork 9
/
Reservoir.cpp
99 lines (91 loc) · 2.85 KB
/
Reservoir.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "Reservoir.h"
#include <stdlib.h>
Reservoir::Reservoir()
{
logger (file, "Reservoir Created.\n");
}
Reservoir::Reservoir(int resDimension)
{
float cue;
srand(CUE_SEED);
resSize[0] = resDimension;
resSize[1] = resDimension;
resSize[2] = resDimension;
logger (file, "Creating Reservoir.\n");
neurons.resize(resSize[0]);
for (int i = 0; i < resSize[0]; i++) {
neurons[i].resize(resSize[1]);
for (int j = 0; j < resSize[1]; j++) {
neurons[i][j].resize(resSize[2]);
for (int k = 0; k < resSize[2]; k++) {
cue = (float)rand()/((float)RAND_MAX/2) - 1; // A random float value between -1 and 1.
neurons[i][j][k] = new Neuron(i, j, k, cue, this);
}
}
}
for (int i = 0; i < resSize[0]; i++) {
for (int j = 0; j < resSize[1]; j++) {
for (int k = 0; k < resSize[2]; k++) {
neurons[i][j][k]->getAxon()->setDirection();
neurons[i][j][k]->getAxon()->growDirection();
}
}
}
logger (file, "Reservoir Successfully Created.\n");
}
Reservoir::Reservoir(int x, int y, int z)
{
float cue;
srand(CUE_SEED);
resSize[0] = x;
resSize[1] = y;
resSize[2] = z;
logger (file, "Creating Reservoir.\n");
neurons.resize(resSize[0]);
for (int i = 0; i < resSize[0]; i++) {
neurons[i].resize(resSize[1]);
for (int j = 0; j < resSize[1]; j++) {
neurons[i][j].resize(resSize[2]);
for (int k = 0; k < resSize[2]; k++) {
cue = (float)rand()/((float)RAND_MAX/2) - 1; // A random float value between -1 and 1.
neurons[i][j][k] = new Neuron(i, j, k, cue, this);
numNeurons += 1;
}
}
}
for (int i = 0; i < resSize[0]; i++) {
for (int j = 0; j < resSize[1]; j++) {
for (int k = 0; k < resSize[2]; k++) {
neurons[i][j][k]->getAxon()->setDirection();
neurons[i][j][k]->getAxon()->growDirection();
}
}
}
logger (file, "Reservoir Successfully Created.\n");
}
Neuron* Reservoir::getNeuron (int x, int y, int z) {
return neurons[x][y][z];
}
int Reservoir::getResDim (int dim) {
int resDim = resSize[dim];
return resDim;
}
Reservoir::~Reservoir()
{
logger (file, "Destroying Reservoir.\n");
for (int i = 0; i < resSize[0]; i++) {
for (int j = 0; j < resSize[1]; j++) {
for (int k = 0; k < resSize[2]; k++) {
delete neurons[i][j][k]->getAxon();
}
}
}
for (int i = 0; i < resSize[0]; i++) {
for (int j = 0; j < resSize[1]; j++) {
for (int k = 0; k < resSize[2]; k++) {
delete neurons[i][j][k];
}
}
}
logger (file, "Reservoir Successfully Destroyed.\n");
}