Inverse transformation by bisection method failed, although succeed by Newton method

Hello Stanimaniacs,

Once I asked how to code inverse transformation by Stan. And then, I learned Newton method.
After that, I noticed my transformation failed when skewness parameter is larger or lesser. So I tried coding inverse transformation by bisection method.

But even though the transformation goes well, checking the expose_stan_function by rstan, the optimization failed by the model. When I saw the error in console, LS failed was printed.
Anyone knows the problem in my code?

The operated codes were located in Google Colab.
The plots of transformation result by rstan were also attached. First one is by bisection’s method, and second one is by Netwon’s method. This transformation uses nu=0.9, and it failed by Netwon’s method as the gradient become steep. So I implemented by bisection method (and it failed!!).

nu09_bisection

nu09_newton

That looks like a function that would cause an iterative root finder to sometimes oscillate. Can you share the current code for the calculation with the solver?

As the optimization works only by the scripts in Google Colab, you mean you’d like to know the scripts of the plot, don’t you? You could reproduce the plot by below scripts. Please save the stan model in Google Colab on your desktop directory before your operation.

library("rstan")
rstan::expose_stan_functions("Desktop/inv_trans_bisection.stan")
x = seq(-pi, pi, length=10000)
inv_transformation_Batschelet(x, mu=0, nu=0.9, I=10000)
y = inv_transformation_Batschelet(x, mu=0, nu=0.9, I=10000)
plot(x, y)