-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.java
More file actions
151 lines (130 loc) · 4.02 KB
/
Copy pathNode.java
File metadata and controls
151 lines (130 loc) · 4.02 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package NEAT;
import java.util.ArrayList;
/**
* Models a neural node that exists in our neural network.
* @author Chance Simmons and Brandon Townsend
* @version 2 April 2019
*/
public class Node {
/** The identification number for this node. */
private int id;
/** The layer our node will be residing 'on'. */
private NodeLayer layer;
/** Sum of the inputs being passed into the node */
private double inputSum;
/** Output of the node */
private double output;
/** List that holds the outgoing links to other nodes */
private ArrayList<Link> outgoingLinks;
/**
* Default constructor for a Node. Will create a node on the hidden layer with a bias of 0.
*/
public Node(int id) {
this(id, NodeLayer.HIDDEN);
}
/**
* Creates a Node that is located on a specified layer with a specified bias.
* @param layer The layer to place this node on.
*/
public Node(int id, NodeLayer layer) {
this.id = id;
this.layer = layer;
this.inputSum = 0;
this.output = 0;
this.outgoingLinks = new ArrayList<Link>();
}
/**
* Constructor that takes in id,layer,input sum, and output value
* @param id the id of the node
* @param layer the layers that this node is a part of
* @param inputSum the sum of the input values
* @param output the value of the output
*/
public Node(int id, NodeLayer layer, double inputSum, double output) {
this.id = id;
this.layer = layer;
this.inputSum = inputSum;
this.output = output;
this.outgoingLinks = new ArrayList<Link>();
}
/**
* Returns the identification number of this node.
* @return The identification number of this node.
*/
public int getId() {
return this.id;
}
/**
* Returns the layer that our node is 'on'.
* @return The layer that our node is 'on'.
*/
public NodeLayer getLayer() {
return layer;
}
/**
* Gets the input sum of this node
* @return the input sum of the node
*/
public double getInputSum() {
return this.inputSum;
}
/**
* Adds the incoming sums to the input sum
* @param sum the sum to be added to the input some
*/
public void addInput(double sum){
this.inputSum += sum;
}
/**
* Sets the output of this node
* @param output the new value of output
*/
public void setOutput(double output){
this.output = output;
}
/**
* Returns the output value of this node.
* @return The output value of this node.
*/
public double getOutput() {
return this.output;
}
/**
* Returns the list of links that this node outputs to.
* @return The list of links that this node outputs to.
*/
public ArrayList<Link> getOutgoingLinks(){
return this.outgoingLinks;
}
/**
* Sigmoid activation function used to activate the node
*/
public void activate() {
if(this.layer != NodeLayer.INPUT){
this.output = (1 /(1 + Math.pow(Math.E,(-1 * this.inputSum))));
}
for(Link link : this.outgoingLinks){
if(link.isEnabled()){
// Get's this link's output node and 'sends' something to it's input.
link.getOutput().addInput(link.getWeight() * this.output);
}
}
this.inputSum = 0;
}
/**
* Checks to see if object passed in is equal to this node.
* @param o the object to check equality with
* @return true if the object is equal to this object.
*/
@Override
public boolean equals(Object o){
boolean result = false;
if(o instanceof Node){
Node node = (Node)o;
if(node.getId() == this.id){
result = true;
}
}
return result;
}
}