Skip to content

Instantly share code, notes, and snippets.

@bayerj
Created January 11, 2012 06:38
Show Gist options
  • Select an option

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

Select an option

Save bayerj/1593407 to your computer and use it in GitHub Desktop.
Theano differentiation through scan
import theano, theano.tensor as T
inpt = T.vector('inpt')
W = T.matrix('weights')
output = T.dot(inpt, W)
d_output_wrt_inpt, _ = theano.map(lambda i: T.grad(output[i], inpt),
T.arange(output.shape[0]))
f = theano.function([inpt, W], d_output_wrt_inpt)
print theano.pp(f.maker.env.outputs[0])
for{inplace,cpu,scan_fn}(Shape_i{1}(weights), 1[int64:int64:int8], Shape_i{1}(weights), weights.T, DimShuffle{1}(_dot22(inpt, weights)), alloc(TensorConstant{(1,) of 0.0}, Shape_i{1}(weights)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment