| 41 | |
| 42 | # so you can test different architectures |
| 43 | class HiddenLayer: |
| 44 | def __init__(self, M1, M2, f=T.nnet.relu, use_bias=True, zeros=False): |
| 45 | if zeros: |
| 46 | W = np.zeros((M1, M2)) |
| 47 | else: |
| 48 | W = np.random.randn(M1, M2) * np.sqrt(2. / M1) |
| 49 | self.W = theano.shared(W) |
| 50 | self.params = [self.W] |
| 51 | self.use_bias = use_bias |
| 52 | if use_bias: |
| 53 | self.b = theano.shared(np.zeros(M2)) |
| 54 | self.params += [self.b] |
| 55 | self.f = f |
| 56 | |
| 57 | def forward(self, X): |
| 58 | if self.use_bias: |
| 59 | a = X.dot(self.W) + self.b |
| 60 | else: |
| 61 | a = X.dot(self.W) |
| 62 | return self.f(a) |
| 63 | |
| 64 | |
| 65 | # approximates pi(a | s) |