-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBrain.pde
More file actions
60 lines (43 loc) · 1.38 KB
/
Brain.pde
File metadata and controls
60 lines (43 loc) · 1.38 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
class Brain {
Perceptron[][] layers; //Perceptron Layers
int layers_num = 2; //Numbers of Layers
int perceptron_num = 4; //Numbers of perceptron for each Layers
Brain( DNA dna ){
layers = new Perceptron[layers_num][perceptron_num];
//Assign the Weights, using the DNA genes, and create the perceptron layers:
for (int i = 0; i < layers_num; ++i) {
for (int j = 0; j < perceptron_num; ++j) {
float[] w = new float[4];
w[0] = dna.genes[16*i + 4*j + 0];
w[1] = dna.genes[16*i + 4*j + 1];
w[2] = dna.genes[16*i + 4*j + 2];
w[3] = dna.genes[16*i + 4*j + 3];
layers[i][j] = new Perceptron(perceptron_num, w);
}
}
}
//Compute the Neural Network Outputs
float[] computeOutput ( float[] inputs ){
float out[][] = new float[layers_num+1][perceptron_num];
out[0] = inputs;
for (int i = 0; i < layers_num; ++i) {
for (int j = 0; j < perceptron_num; ++j) {
out[i+1][j] = layers[i][j].feedforward( out[i] );
out[i+1][j] = layers[i][j].feedforward( out[i] );
out[i+1][j] = layers[i][j].feedforward( out[i] );
out[i+1][j] = layers[i][j].feedforward( out[i] );
}
}
return out[layers_num];
}
//Print the Weights:
void printWeights (){
println("Weights: ");
for (int i = 0; i < layers_num; ++i) {
for (int j = 0; j < perceptron_num; ++j) {
println (layers[i][j].weights);
}
}
println("........");
}
}