-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.pde
52 lines (46 loc) · 1.18 KB
/
Node.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
class Node {
int number;
float inputSum = 0;
ArrayList<ConnectionGene> outputConnections = new ArrayList<ConnectionGene>();
float outputValue = 0;
int layer = 0;
PVector drawPos = new PVector();
Node(int no) {
number = no;
}
void engage() {
if (layer!=0) {
outputValue = sigmoid(inputSum);
}
for (int i = 0; i < outputConnections.size(); i++) {
if (outputConnections.get(i).enabled) {
outputConnections.get(i).toNode.inputSum += outputConnections.get(i).weight * outputValue;
}
}
}
float sigmoid (float x) {
return 1 / (1 + pow((float)Math.E, -4.9*x));
}
boolean isConnectedTo(Node node) {
if (node.layer == layer)return false;
if (node.layer < layer) {
for (int i = 0; i < node.outputConnections.size(); i++) {
if (node.outputConnections.get(i).toNode == this) {
return true;
}
}
} else {
for (int i = 0; i < outputConnections.size(); i++) {
if (outputConnections.get(i).toNode == node) {
return true;
}
}
}
return false;
}
Node clone() {
Node clone = new Node(number);
clone.layer = layer;
return clone;
}
}