Hi guys, I noticed that your brent solver isn't using the initial guess
given by the user. This can often radically improve the performance of the
solver. In my tests, it improved it by roughly 30% or more, with a decent
guess. Basically, we should try the guess first. If that's close enough,
rreturn it. Otherwise, try one of the end points. If that's close enough,
return it. Then if that brackets, go into the main loop. If that doesn't
bracket, then we instead try the other endpoint. If that's close enough,
return it. If that doesn't bracket, throw an exception. If it does bracket,
go into the main loop with all three trial points available, allowing the
quadratic interpolation to be used immediately.
Worst case scenario, the initial guess doesn't bracket. In that case it is
better than the default algorithm only if the user's initial guess is better
than linear interpolation, which I imagine it almost always would be. If the
user can't guess better than linear interpolation, presumably they wouldn't
provide a guess at all, and then nothing would change.
It's a small addition, less than 100 lines of code. I can't send it in due
to legal at work, but from the above ideas, you should be able to put it in
easily. One caveat. You may need to slightly modify the baisic solve(double,
double) method to linearly interpolate a good beginning point and then break
out a six double (solve(x0, y0, x1, y1, x2, y2)) method that both solve(min,
max) and solve(min, max, initial) can use. If you don't do this, then
solve(min, max) will bisect on its first iteration rather than intepolating,
which could cost performance. If you do break it out like so, then this will
always perform better than the current implementation.
