Algebra_solver issues and what are the defaults for the optional arguments

Hi,

I’m getting sometimes this "Chain 1 Exception: Exception: algebra_solver: the norm of the algebraic function is 24.6913 but should be lower than the function tolerance: 1e-06. Consider decreasing the relative tolerance and increasing max_num_steps. " with the algebra solver.

I couldn’t find much info about the optional arguments in the documentation, what are the defaults?

  • rel_tol : relative tolerance for the algebraic solver, type real , data only,
  • function_tol : function tolerance for the algebraic solver, type real , data only,
  • max_num_steps : maximum number of steps to take in the algebraic solver, type int , data only.

Also what’s the difference between the two “tol” arguments.

And something else, two strange things:

  • newton method doesn’t seem to work for me, while the default does.
  • does it make sense that with a “good” guess the model gets stuck in the initial values more often than just guessing 0? By good I mean that sometimes I can get the analytical solution of the equation and I plug it as guess, and sometimes I can’t (because of numerical issues). I’m a bit hesitant of pasting the monstrosity of my model and scare away answers :)

Bruno

(BTW, shouldn’t there be a tag for the solvers?)

Hi, I think the defaults for the Powell method (which I think is the default, but I am not sure) are at https://github.com/stan-dev/math/blob/cbf1e572bb9d6f3f9469d43b56246d6b98436346/stan/math/rev/functor/algebra_solver_powell.hpp#L129 the same for Newton method at: https://github.com/stan-dev/math/blob/cbf1e572bb9d6f3f9469d43b56246d6b98436346/stan/math/rev/functor/algebra_solver_newton.hpp#L62

The code comments also have that:

* @param[in] relative_tolerance determines the convergence criteria
 *            for the solution.
 * @param[in] function_tolerance determines whether roots are acceptable.
* @param[in] max_num_steps  maximum number of function evaluations.

Not sure what you mean by “stuck” - do you mean that you the “cannot initialize after 100 attempts” thing?

Anyway, I think the most likely cause is an actual numerical problem in the way you coded the equation, and while fiddling with tolerances might help a bit, it doesn’t look like you are “slightly out of range” but rather that something really bad is happening. However, without code, can’t help much more.

It is my impression that Newton is supposed to be faster but not suitable for all problems, so that sounds unsurprising.

Created :-)

Thanks!
I managed to make the solver work ignoring my analytical solution, and I don’t want to waste people’s time with the monstrosity of my model.
I’ll save it for when I’m truly stuck. :)
I still don’t get the meaning of the optional parameters. But I guess I’ll open an issue in documentation so that someone puts a relevant link. I guess this should be documented somewhere maybe in the relevant cpp function?

1 Like