Skip to content

Instantly share code, notes, and snippets.

@zaltoprofen
Created November 5, 2014 13:03
Show Gist options
  • Select an option

  • Save zaltoprofen/1674bae4448c3535af91 to your computer and use it in GitHub Desktop.

Select an option

Save zaltoprofen/1674bae4448c3535af91 to your computer and use it in GitHub Desktop.
import theano
import theano.tensor as T
EPS=1E-10
x=T.dscalar('x')
y=(x-3)**2 - T.log(x)
dy = T.grad(y,x)
ddy = T.grad(dy,x)
f = theano.function([x], y)
next_x = theano.function([x], x-dy/ddy)
x = 10
dx = 1
while dx > EPS:
print("y=%12.10g\tx=%12.10g" % (f(x),x))
nx = next_x(x)
dx = abs(nx - x)
x = nx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment