ihmeuw-msca / CurveFit

Generic curve fitting package with nonlinear mixed effects model
https://ihmeuw-msca.github.io/CurveFit/
GNU General Public License v3.0
191 stars 57 forks source link

Refactor: use AD to evaluate objective and gradient during optimization. #101

Closed bradbell closed 4 years ago

bradbell commented 4 years ago

This change is very minimal change that is meant to be an example of how AD can be used to speed up evaluation of a function and to evaluate its derivatives. I have not included Hessians, or sparse derivatives but there are lots of other things that could be calculated.

The AD version of the objective and the gradient should be much faster than the current version. It would be good to test and quantify this.

The important point is that all the arguments to the function that can change are included in the independent variable declartion:

ax = cppad_py.independent(x)
bradbell commented 4 years ago

Travis cannot find cppad_py:

import cppad_py E ModuleNotFoundError: No module named 'cppad_py'

bradbell commented 4 years ago

I finally got cppad_py to load into the tests using a wrapper bin/run_tests.sh that sets LD_LIBRARY_PATH and then executes pytest and the other tests.

Now there is some other problem in the travis environment. the divide operator is not defined for ad types.

    E       TypeError: unsupported operand type(s) for /: 'a_double' and 'float'

To fix this I would need a local copy of the travis virtual machine in a docker image which I do not know how to create.