-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeuron.java
52 lines (41 loc) · 1.36 KB
/
Neuron.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
package code.NN;
import java.io.Serializable;
/**
* @author Alexandre Martens
*/
public class Neuron implements Serializable {
static float minWeightValue;
static float maxWeightValue;
float[] weights;
float[] weightsCache; // Used in backpropagation. Stores the new calc weights without replacing the original ones (= weights). We need them to calculate the next layer
float gradient; // Speed up calculations, because a lot of reuse of data
float bias;
float value = 0;
// Constructor input neurons
public Neuron(float value){
this.value = value;
this.bias = -1;
this.gradient = -1;
this.weights = null;
this.weightsCache = null;
}
// Constructor hidden/output neurons
public Neuron(float[] weights, float bias){
this.weights = weights;
this.weightsCache = this.weights;
this.bias = bias;
this.gradient = 0;
}
// Set min and max range for the weights
public static void setRangeWeight(float min, float max){
minWeightValue = min;
maxWeightValue = max;
}
// At the end of the backpropagation, replace the old/original weights (= weights) with the new calculated ones (= weightsCache)
public void updateWeights(){
this.weights = this.weightsCache;
}
public float getValue() {
return value;
}
}