-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayer.pde
More file actions
52 lines (43 loc) · 1.26 KB
/
Layer.pde
File metadata and controls
52 lines (43 loc) · 1.26 KB
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
class Layer implements Iterable<Neuron> {
// layer in the neural network
Network network;
ArrayList<Neuron> neurons = new ArrayList<Neuron>();
int layer;
float neuronDisplaySize;
Layer(Network network, int layer) {
this.network = network;
this.layer = layer;
}
Layer(Network network, int numNeurons, int layer) {
this.network = network;
for (int i = 0; i < numNeurons; i++) {
neurons.add(new Neuron(network, layer, i));
}
this.layer = layer;
}
Neuron get(int i) {
try {
return neurons.get(i);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
return neurons.get(0);
}
}
Neuron getRandom() { return neurons.get(floor(random(neurons.size()))); }
Iterator<Neuron> iterator() { return neurons.iterator(); }
Neuron add(Neuron neuron) {
neurons.add(neuron);
return neuron;
}
void shiftLayer() {
layer++;
neurons.forEach(n->n.shiftLayer());
}
Layer copy(Network network) {
Layer copy = new Layer(network, layer);
for (Neuron neuron : neurons) {
copy.neurons.add(neuron.copy(network));
}
return copy;
}
}