-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetwork.pde
65 lines (43 loc) · 1.32 KB
/
Network.pde
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
class Network {
int layerLoopCount = 0;
PVector location;
int layerCount;
int[] layerSize;
color[] layerColor;
ArrayList<Layer> layers;
Network(int layerC, int[] layerS, color[] layerCol) {
location = new PVector(width/2, height/2);
layerCount = layerC;
layerSize = layerS;
color[] layerColor = layerCol;
layers = new ArrayList<Layer>();
for(int i = 0; i < layerCount; i++) {
float inc = (float)i/((float)layerCount-1.0);
float x = (width - 100) / (2);
x = lerp(-x, x,inc);
Layer l = new Layer(i, layerSize[i], layerColor[i], x);
layers.add(l);
}
for(int i = 0; i < layerCount - 1; i++) {
ArrayList<Neuron> nextNeurons = layers.get(i+1).neurons;
ArrayList<Neuron> neurons = layers.get(i).neurons;
for(int j = 0; j < neurons.size(); j++) {
neurons.get(j).connect(nextNeurons);
}
}
}
//We can draw the entire network.
void display() {
pushMatrix();
translate(location.x, location.y);
for (Layer l : layers) {
l.display();
}
popMatrix();
}
void feedforward() {
layers.get(layerLoopCount).feedforward(0);
layerLoopCount += 1;
if(layerLoopCount >= layers.size() - 1) layerLoopCount = 0;
}
}