MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / HiddenLayer

Class HiddenLayer

rl2/mountaincar/pg_tf.py:27–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected