-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathNeuralNetwork.java
More file actions
42 lines (34 loc) · 806 Bytes
/
Copy pathNeuralNetwork.java
File metadata and controls
42 lines (34 loc) · 806 Bytes
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
package model;
import java.util.ArrayList;
import java.util.List;
import matrix.Matrix;
import autodiff.Graph;
public class NeuralNetwork implements Model {
private static final long serialVersionUID = 1L;
List<Model> layers = new ArrayList<>();
public NeuralNetwork(List<Model> layers) {
this.layers = layers;
}
@Override
public Matrix forward(Matrix input, Graph g) throws Exception {
Matrix prev = input;
for (Model layer : layers) {
prev = layer.forward(prev, g);
}
return prev;
}
@Override
public void resetState() {
for (Model layer : layers) {
layer.resetState();
}
}
@Override
public List<Matrix> getParameters() {
List<Matrix> result = new ArrayList<>();
for (Model layer : layers) {
result.addAll(layer.getParameters());
}
return result;
}
}