| 26 | |
| 27 | # so you can test different architectures |
| 28 | class HiddenLayer: |
| 29 | def __init__(self, M1, M2, f=tf.nn.tanh, use_bias=True): |
| 30 | self.W = tf.Variable(tf.random_normal(shape=(M1, M2))) |
| 31 | self.use_bias = use_bias |
| 32 | if use_bias: |
| 33 | self.b = tf.Variable(np.zeros(M2).astype(np.float32)) |
| 34 | self.f = f |
| 35 | |
| 36 | def forward(self, X): |
| 37 | if self.use_bias: |
| 38 | a = tf.matmul(X, self.W) + self.b |
| 39 | else: |
| 40 | a = tf.matmul(X, self.W) |
| 41 | return self.f(a) |
| 42 | |
| 43 | |
| 44 | # approximates pi(a | s) |