Skip to content

Instantly share code, notes, and snippets.

@yukoba
Last active September 9, 2016 04:39
Show Gist options
  • Save yukoba/5c643f70587f84e4ec7f9e7221cfc710 to your computer and use it in GitHub Desktop.
Save yukoba/5c643f70587f84e4ec7f9e7221cfc710 to your computer and use it in GitHub Desktop.
Steepest descent method using theano.scan()
import theano
import theano.tensor as T
# Steepest descent method using theano.scan()
def fn(x, learning_rate):
y = x ** 2 - x
return x - learning_rate * T.grad(y, x)
init_x = T.dscalar()
result, updates = theano.scan(fn=fn,
outputs_info=init_x,
non_sequences=0.3,
n_steps=100)
f2 = theano.function([init_x], result[-1], updates=updates)
print(f2(1)) # 0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment