提交 1b0f3caa authored 作者: Frederic's avatar Frederic

pep8

上级 18d6b9de
...@@ -37,7 +37,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -37,7 +37,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
b_sym = T.vector("b_sym") b_sym = T.vector("b_sym")
results, updates = theano.scan(lambda v:T.tanh(T.dot(v, W)+b_sym), sequences=X) results, updates = theano.scan(lambda v:T.tanh(T.dot(v, W)+b_sym), sequences=X)
compute_elementwise = theano.function(inputs = [X, W, b_sym], outputs=[results]) compute_elementwise = theano.function(inputs=[X, W, b_sym], outputs=[results])
# test values # test values
x = np.eye(2) x = np.eye(2)
...@@ -70,7 +70,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -70,7 +70,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
results, updates = theano.scan(lambda results, updates = theano.scan(lambda
y,p,x_tm1:T.tanh(T.dot(x_tm1, W)+T.dot(y, U)+T.dot(p, V)), y,p,x_tm1:T.tanh(T.dot(x_tm1, W)+T.dot(y, U)+T.dot(p, V)),
sequences=[Y, P[::-1]], outputs_info=[X]) sequences=[Y, P[::-1]], outputs_info=[X])
compute_seq = theano.function(inputs = [X, W, Y, U, P, V], outputs=[results]) compute_seq = theano.function(inputs=[X, W, Y, U, P, V], outputs=[results])
# test values # test values
x = np.zeros((2)) x = np.zeros((2))
...@@ -101,7 +101,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -101,7 +101,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
# define tensor variable # define tensor variable
X = T.matrix("X") X = T.matrix("X")
results, updates = theano.scan(lambda x_i:T.sqrt((x_i**2).sum()), sequences=[X]) results, updates = theano.scan(lambda x_i:T.sqrt((x_i**2).sum()), sequences=[X])
compute_norm_lines = theano.function(inputs = [X], outputs=[results]) compute_norm_lines = theano.function(inputs=[X], outputs=[results])
# test value # test value
x = np.diag(np.arange(1, 6), 1) x = np.diag(np.arange(1, 6), 1)
...@@ -120,7 +120,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -120,7 +120,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
# define tensor variable # define tensor variable
X = T.matrix("X") X = T.matrix("X")
results, updates = theano.scan(lambda x_i:T.sqrt((x_i**2).sum()), sequences=[X.T]) results, updates = theano.scan(lambda x_i:T.sqrt((x_i**2).sum()), sequences=[X.T])
compute_norm_cols = theano.function(inputs = [X], outputs=[results]) compute_norm_cols = theano.function(inputs=[X], outputs=[results])
# test value # test value
x = np.diag(np.arange(1, 6), 1) x = np.diag(np.arange(1, 6), 1)
...@@ -143,7 +143,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -143,7 +143,7 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
sequences=[T.arange(X.shape[0]), T.arange(X.shape[1])], sequences=[T.arange(X.shape[0]), T.arange(X.shape[1])],
outputs_info=np.asarray(0., dtype=floatX)) outputs_info=np.asarray(0., dtype=floatX))
result = results[-1] result = results[-1]
compute_trace = theano.function(inputs = [X], outputs=[result]) compute_trace = theano.function(inputs=[X], outputs=[result])
# test value # test value
x = np.eye(5) x = np.eye(5)
...@@ -169,8 +169,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -169,8 +169,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
n_sym = T.iscalar("n_sym") n_sym = T.iscalar("n_sym")
results, updates = theano.scan(lambda x_tm2, x_tm1:T.dot(x_tm2, U) + T.dot(x_tm1, V) + T.tanh(T.dot(x_tm1, W) + b_sym), results, updates = theano.scan(lambda x_tm2, x_tm1:T.dot(x_tm2, U) + T.dot(x_tm1, V) + T.tanh(T.dot(x_tm1, W) + b_sym),
n_steps=n_sym, outputs_info=[dict(initial = X, taps = [-2, -1])]) n_steps=n_sym, outputs_info=[dict(initial=X, taps=[-2, -1])])
compute_seq2 = theano.function(inputs = [X, U, V, W, b_sym, n_sym], outputs=[results]) compute_seq2 = theano.function(inputs=[X, U, V, W, b_sym, n_sym], outputs=[results])
# test values # test values
x = np.zeros((2, 2)) # the initial value must be able to return x[-2] x = np.zeros((2, 2)) # the initial value must be able to return x[-2]
...@@ -203,8 +203,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`. ...@@ -203,8 +203,8 @@ The full documentation can be found in the library: :ref:`Scan <lib_scan>`.
v = T.vector() v = T.vector()
A = T.matrix() A = T.matrix()
y = T.tanh(T.dot(v, A)) y = T.tanh(T.dot(v, A))
results, updates = theano.scan(lambda i:T.grad(y[i], v), sequences = [T.arange(y.shape[0])]) results, updates = theano.scan(lambda i:T.grad(y[i], v), sequences=[T.arange(y.shape[0])])
compute_jac_t = theano.function([A, v], [results], allow_input_downcast = True) # shape (d_out, d_in) compute_jac_t = theano.function([A, v], [results], allow_input_downcast=True) # shape (d_out, d_in)
# test values # test values
x = np.eye(5)[0] x = np.eye(5)[0]
...@@ -229,7 +229,7 @@ Note that we need to iterate over the indices of ``y`` and not over the elements ...@@ -229,7 +229,7 @@ Note that we need to iterate over the indices of ``y`` and not over the elements
n_sym = T.iscalar("n_sym") n_sym = T.iscalar("n_sym")
results, updates = theano.scan(lambda:{k:(k+1)}, n_steps=n_sym) results, updates = theano.scan(lambda:{k:(k+1)}, n_steps=n_sym)
accumulator = theano.function([n_sym], [], updates=updates, allow_input_downcast = True) accumulator = theano.function([n_sym], [], updates=updates, allow_input_downcast=True)
k.get_value() k.get_value()
accumulator(5) accumulator(5)
...@@ -252,8 +252,8 @@ Note that we need to iterate over the indices of ``y`` and not over the elements ...@@ -252,8 +252,8 @@ Note that we need to iterate over the indices of ``y`` and not over the elements
d=trng.binomial(size=W[1].shape) d=trng.binomial(size=W[1].shape)
results, updates = theano.scan(lambda v:T.tanh(T.dot(v, W)+b_sym)*d, sequences=X) results, updates = theano.scan(lambda v:T.tanh(T.dot(v, W)+b_sym)*d, sequences=X)
compute_with_bnoise = theano.function(inputs = [X, W, b_sym], outputs=[results], compute_with_bnoise = theano.function(inputs=[X, W, b_sym], outputs=[results],
updates=updates, allow_input_downcast = True) updates=updates, allow_input_downcast=True)
x = np.eye(10, 2) x = np.eye(10, 2)
w = np.ones((2, 2)) w = np.ones((2, 2))
b = np.ones((2)) b = np.ones((2))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论