![]() |
Prev | Next | get_started.py |
pycppad
and then checks the results for correctness:
from pycppad import *
def pycppad_test_get_started() :
def F(x) : # function to be differentiated
return exp(-(x[0]**2. + x[1]**2.) / 2.) # is Gaussian density
x = numpy.array( [ 1., 2.] )
a_x = independent(x)
a_y = numpy.array( [ F(a_x) ] )
f = adfun(a_x, a_y)
J = f.jacobian(x) # J = F'(x)
assert abs( J[0, 0] + F(x) * x[0] ) < 1e-10 # J[0,0] ~= - F(x) * x[0]
assert abs( J[0, 1] + F(x) * x[1] ) < 1e-10 # J[0,1] ~= - F(x) * x[1]