Skip to content

Instantly share code, notes, and snippets.

@bayerj
Created January 27, 2011 12:42
Show Gist options
  • Select an option

  • Save bayerj/798456 to your computer and use it in GitHub Desktop.

Select an option

Save bayerj/798456 to your computer and use it in GitHub Desktop.
W = T.matrix('weights')
initial = T.vector('initial')
inpt = T.matrix('inpt')
def one_step(x_t, h_tm1, W):
expr = dot(h_tm1, W) + x_t
return expr
expr, _ = theano.scan(
fn=one_step,
sequences=[inpt],
outputs_info=[initial],
non_sequences=[W])
sh = expr.shape[0]
shapef = theano.function([W], sh,
givens={initial: theano.shared(scipy.ones(5)),
inpt: theano.shared(scipy.ones((5, 5)))})
print shapef(scipy.ones((5, 5)))
cost = expr.sum()
f = theano.function([W], cost,
givens={initial: theano.shared(scipy.ones(5)),
inpt: theano.shared(scipy.ones((5, 5)))})
print f(scipy.ones((5, 5)))
f2 = theano.function([W, inpt], cost,
givens={initial: scipy.zeros(5)})
print f2(scipy.ones((5, 5)), scipy.ones((10, 5)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment