Newton solver now exposed to Stan language

The Newton solver, based on KINSOL, is now exposed to the Stan language and in the master branch of stanc3. Its signature is identical to the previous solver:

algebra_solver_newton(system, y_guess, theta, x_r, x_i, 
                      rel_tol, f_tol, max_num_steps)

You can still use the original solver, based on Powell’s dogleg method, via algebra_solver(). In my experience, the Newton method is better to much better than Powell, so I recommend using it as a default.

This update is long overdue, so sorry for the delay. I wasn’t sure there’d be much use for it (but folks have been requesting this feature) and was also holding off to add the below-described features, but it seems better to go at it step-by-step. Thank you, @rok_cesnovar for reviewing the PR!

Where we go next

We’ll use two signatures and deprecate the original signature, much like was done for the ode integrator:

  • algebra_solver_newton()
  • algebra_solver_powell()
  • algebra_solver() (deprecated)

Still following the example of the ODE integrators, the algebraic solver will take in variadic arguments (and/or closures). Using @bbbales2’s work on nested backward autodiff, we’ll also improve the differentiation, using an adjoint method.

@wds15 @yizhang

8 Likes

Nice thanks!

stanc3 has a vey nice, but little know flag “–print-canonical” that in addition to other cleanups, replaces deprecated functions using non-deprecated ones. Any thoughts on what should we do here: replace with _powell so we remain numerically consistent or replace with _newton which you say is much better?

also tagging @nhuurre, the author of the “canonicalizer”, maybe there is already some precedent here that requires us to use _powell for consistency.

I am not sure on this one specifically, but it sounds like you would even standardize integrate_ode calls… which one should not. So I think if a user requests Powell, then he should get that.

No no, —print-canonical does not try to be smart about such stuff. Just replaces deprecated signatures. For example multiply_log is replaced by lmultiply, integrate_ode is replaced with the explicit call to integrate_ode_rk45, etc. So probably I answered myself and it should just use algebra_solver_powell explicitly.

1 Like