Hi Chapel community ,
I am happy to share I got my first (and definitely not last) library released in mason: ForwardModeAD.
It is a simple library for automatic differentiation using forward-mode and operator/function overloading. Here is a sneak preview of how to use it (to implement the Newton method for root finding).
use ForwardModeAD;
proc f(x) {
return exp(-x) * sin(x) - log(x);
}
var tol = 1e-6, // tolerance to find the root
cnt = 0, // to count number of iterations
x0 = initdual(0.5), // initial guess
valder = f(x0); // initial function value and derivative
while abs(value(valder)) > tol {
x0 -= value(valder) / derivative(valder);
valder = f(x0);
cnt += 1;
writeln("Iteration ", cnt, " x = ", value(x0), " residual = ", value(valder));
}
Iteration 1 x = 1.05953 residual = 0.244472
Iteration 2 x = 1.28662 residual = 0.0131033
Iteration 3 x = 1.3002 residual = 4.13149e-05
Iteration 4 x = 1.30025 residual = 4.13897e-10
Currently it supports derivatives, gradients, jacobians, directional derivatives and jacobian-vector product.
The library is at early stages and still maturing, all sort of feedback, comments, suggestions, bug reports, feature requests etc. etc. are warmly welcome.
repository:
documentation:
https://forwardmodead.readthedocs.io/en/stable/