-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXOR.java
More file actions
64 lines (42 loc) · 1.52 KB
/
Copy pathXOR.java
File metadata and controls
64 lines (42 loc) · 1.52 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
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
* Created by mujtaba on 26/04/15.
*/
public class XOR {
public static void main(String[] args) {
Example[] examples = new Example[]{
new Example(new double[]{0,0},new double[]{0}),
new Example(new double[]{0,1},new double[]{1}),
new Example(new double[]{1,0},new double[]{1}),
new Example(new double[]{1,1},new double[]{0})
};
MLP mlp = new MLP(2,2,1);
try {
PrintWriter fout = new PrintWriter(new FileWriter("XOR.text"));
fout.println("#\tX\tY");
for (int i = 0; i < 100000; ++i) {
double error = 0.0;
for (int l = 0; l < examples.length; ++l) {
double[] output = mlp.forward(examples[l].input);
error += mlp.backwards( output,examples[l].output);
}
mlp.updateWeights(0.3);
if(i % 100 == 1) {
System.out.println(i + " -> error : " + error);
fout.println("\t" + i + "\t" + error);
}
}
fout.close();
} catch (IOException e){
e.printStackTrace();
}
// test the result
System.out.println("MLP output : Actual output");
for(int i = 0 ; i < examples.length; i++){
double[] out= mlp.forward(examples[i].input);
System.out.println(out[1] + " : "+ examples[i].output[0]);
}
}
}