AutoDiff
21/02/21
I've been playing around with AutoDiff lately and have managed to get it working with R through Rcpp and CppAd. In particular, I've put together some code to find minima of functions using optimisation routines built-in to R. For example, we can write down the following function
// C++
class F : public Function {
a_double fn(const av_double &x) {
return 100 * pow(x[1] - x[0]*x[0], 2) + pow(1-x[0], 2);
}
};
And have it optimised by calling
// C++
F func;
func.set_grad(x);
minimise(func, x, x_out);
I've omitted some code for clarity, but the full repo with more examples can be found here.