-
Notifications
You must be signed in to change notification settings - Fork 0
/
Perceptron.java
77 lines (62 loc) · 1.41 KB
/
Perceptron.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
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
import java.util.*;
import java.io.*;
public class Perceptron implements Serializable {
private List<Double> weights;
private double output;
private double errorSignal;
public Perceptron() {
weights = new ArrayList<Double>(0);
double output = 0;
double errorSignal = 0;
}
public Perceptron(ArrayList<Double> weightList) {
weights = weightList;
double output = 0;
double errorSignal = 0;
}
public Perceptron(int size) {
weights = new ArrayList<Double>(size);
for (int i = 0; i < size; i++) {
weights.add(1.0/((double)size));
}
double output = 0;
double errorSignal = 0;
}
public void setOutput(double ou) {
output = ou;
}
public double getOutput() {
return output;
}
public void setErrorSignal(double es) {
errorSignal = es;
}
public double getErrorSignal() {
return errorSignal;
}
public List<Double> getWeights() {
return weights;
}
public Double getWeight(int i) {
return weights.get(i);
}
public void setWeights(List<Double> weightList) {
weights = weightList;
}
public void setWeight(int i, double weight) {
weights.set(i,weight);
}
public void changeWeight(int i, double change) {
weights.set(i, weights.get(i)+change);
}
public double out(List<Double> in) {
double total = 0;
for (int i = 0; i < in.size(); i++) {
total += (in.get(i) * weights.get(i));
}
return phi(total);
}
private double phi(double x) {
return 1.0/(1+Math.exp(-x));
}
}