Permalink
Browse files

added gradient comparison to pyadolc vs pycppad

  • Loading branch information...
1 parent efdabec commit b888a5fcf095654d3a798b1d3033718ee47af952 basti committed Jul 15, 2009
@@ -8,12 +8,14 @@
if __name__ == "__main__":
- N_max = 200
- reps = 30
+ N_max = 120
+ reps = 100
Ns = range(2,N_max,5)
- adolc_runtimes = []
- cppad_runtimes = []
+ adolc_gradient_runtimes = []
+ cppad_gradient_runtimes = []
+ adolc_hessian_runtimes = []
+ cppad_hessian_runtimes = []
for N in Ns:
@@ -29,8 +31,8 @@
x = numpy.random.rand(N)
w = numpy.array( [ 1.] ) # compute Hessian of x0 * sin(x1)
- cppad_runtime = timeit.Timer('f.hessian(x, w)', 'from __main__ import f,x,w').timeit(number=reps)/reps
-
+ cppad_hessian_runtime = timeit.Timer('f.hessian(x, w)', 'from __main__ import f,x,w').timeit(number=reps)/reps
+ cppad_gradient_runtime = timeit.Timer('f.jacobian(x)', 'from __main__ import f,x').timeit(number=reps)/reps
# adolc timing
x = numpy.zeros(N, dtype=float)
@@ -45,17 +47,26 @@
adolc.trace_off()
x = numpy.random.rand(N)
- adolc_runtime = timeit.Timer('adolc.hessian(0, x)', 'import adolc;from __main__ import x').timeit(number=reps)/reps
-
- adolc_runtimes.append(adolc_runtime)
- cppad_runtimes.append(cppad_runtime)
+ adolc_hessian_runtime = timeit.Timer('adolc.hessian(0, x)', 'import adolc;from __main__ import x').timeit(number=reps)/reps
+ adolc_gradient_runtime = timeit.Timer('adolc.gradient(0, x)', 'import adolc;from __main__ import x').timeit(number=reps)/reps
+
+ adolc_hessian_runtimes.append(adolc_hessian_runtime)
+ cppad_hessian_runtimes.append(cppad_hessian_runtime)
+
+ adolc_gradient_runtimes.append(adolc_gradient_runtime)
+ cppad_gradient_runtimes.append(cppad_gradient_runtime)
pylab.figure()
- pylab.semilogy(Ns, adolc_runtimes, '-b.', label='pyadolc')
- pylab.semilogy(Ns, cppad_runtimes, '-r.', label='pycppad')
+ pylab.semilogy(Ns, adolc_hessian_runtimes, '-b.', label='hessian pyadolc')
+ pylab.semilogy(Ns, adolc_gradient_runtimes, '-bd', label='gradient pyadolc')\
+
+ pylab.semilogy(Ns, cppad_hessian_runtimes, '-r.', label='hessian pycppad')
+ pylab.semilogy(Ns, cppad_gradient_runtimes, '-rd', label='gradient pycppad')
+
+
pylab.xlabel(r'problem size $N$')
- pylab.ylabel(r'runtime t [sec]')
- pylab.title(r'Hessian computation')
- pylab.legend()
+ pylab.ylabel(r'average runtime $t= \frac{1}{%d} \sum_{r=1}^{%d} t_r$ in [sec]'%(reps,reps))
+ pylab.title(r'Hessian/Gradient computation, %d runs '%reps)
+ pylab.legend(loc=2)
pylab.savefig('runtimes_pycppad_pyadolc.png')
pylab.show()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b888a5f

Please sign in to comment.