-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected results from Brent minimizer. #174
Comments
I used this opportunity to create a nice visual debugging notebook in Maria, thanks to @mhuebert: https://2.maria.cloud/gist/e2e9fa24033f5b50d6cc7af44f22243f The difference with scmutils was the initial condition for Brent. Apache Math-Commons used the midpoint between the left and right ends of the interval, while the original algorithm, and scmutils, used a golden section cut. It doesn't matter usually, but in this case the difference pushed you to a different local minimum. I'm going to fix / change this to match scmutils in #175 . The real thing you want to use is #114 , and that would be an awesome contribution @alexgian if you're willing to work on it. |
Does this mean that in different circumstances choosing the midpoint between left and right would have been the better choice? Or is a Golden Section cut always preferred? If the the former is the case, then it needs be an option, I think. Yeah, I'll look at #114, Sam. |
@alexgian I think this is an edge case for the algorithm and there's no general answer here. I did provide a new option for I'll close this now since this is fixed in #175 , and that's under review now by @littleredcomputer . Thanks @alexgian ! |
Unexpected results from Brent minimizer:
I came across this problem when trying to find the nearest point on a parametric curve (in this case an ellipse) to a random given point in its vicinity. I tried minimizing the distance formula, the difference between the two points.
Obviously you'd expect such distances around an ellipse to be symmetrical about the axes, but I found a large section of the ellipse, pizza-slice shaped, gave unlikely to very unlikely results.
I tried the code in GJS' scmultils, and the answers were correct there. Checked the default values for eps tolerances, adjusted them, but the results were still way out.
Here's the code, both scmutils and Emmy.
gives
All correct and symmetric as it should be. OTOH with the Emmy code:
running in REPL...
Symmetry is just not there.
However, in every case the first value of each pair matches pretty well with the scmutils results.
Basically, I wanted to apply this function to an
emmy-viewers.mafs/moveable-point
to constrain it to move on an ellipse that is specified parametrically. This is a bit more elegant than using x-y coordinates and conditionals (which kinda works, but feels klutzy).The text was updated successfully, but these errors were encountered: