-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.java
52 lines (51 loc) · 1.37 KB
/
Node.java
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
import java.util.*;
public class Node {
private float value;
private float error;
private ArrayList<Connection> inConnections = new ArrayList<Connection>();
private ArrayList<Connection> outConnections = new ArrayList<Connection>();
public Node() {
Random r = new Random();
this.value = r.nextFloat() * 2 - 1;
}
public Node(Node[] prevNodes) {
for (Node prevNode : prevNodes) {
Connection c = new Connection(prevNode, this);
this.inConnections.add(c);
prevNode.setOutConnection(c);
}
this.propagate();
}
public void propagate() {
float activation = 0.0f;
for (Connection c : inConnections) {
activation += c.getValueContribution();
}
this.value = 1.0f / (1.0f + (float)Math.exp(-1.0f*activation));
}
public void setOutConnection(Connection c) {
this.outConnections.add(c);
}
public void setValue(float value) {
this.value = value;
}
public float getValue() {
return this.value;
}
public ArrayList<Connection> getInConnections() {
return this.inConnections;
}
public void setError() {
float totalError = 0.0f;
for (Connection c : this.outConnections) {
totalError += c.getErrorContribution();
}
this.error = this.value * (1 - this.value) * totalError;
}
public void setError(float error) {
this.error = error;
}
public float getError() {
return this.error;
}
}