-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathFeedForwardLayer.java
More file actions
42 lines (33 loc) · 892 Bytes
/
Copy pathFeedForwardLayer.java
File metadata and controls
42 lines (33 loc) · 892 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 java.util.Random;
import matrix.Matrix;
import autodiff.Graph;
public class FeedForwardLayer implements Model {
private static final long serialVersionUID = 1L;
Matrix W;
Matrix b;
Nonlinearity f;
public FeedForwardLayer(int inputDimension, int outputDimension, Nonlinearity f, double initParamsStdDev, Random rng) {
W = Matrix.rand(outputDimension, inputDimension, initParamsStdDev, rng);
b = new Matrix(outputDimension);
this.f = f;
}
@Override
public Matrix forward(Matrix input, Graph g) throws Exception {
Matrix sum = g.add(g.mul(W, input), b);
Matrix out = g.nonlin(f, sum);
return out;
}
@Override
public void resetState() {
}
@Override
public List<Matrix> getParameters() {
List<Matrix> result = new ArrayList<>();
result.add(W);
result.add(b);
return result;
}
}