-
Notifications
You must be signed in to change notification settings - Fork 19
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
Hessian performance #293
Comments
Hmmn, that's not great. I'm not sure I'd call 37 parameters modestly sized though ;)
|
GraidentModel takes 32 seconds. Actually, on closer inspection, the model has 27 parameters. Math is hard. But compared to the ~300 parameter model I would like to fit, its still modest. |
Sounds much better. Still long-ish, but I'd say acceptable. Even 200s could be considered acceptable, depending on the application
That's somewhere between strange and worrying. All Models should result in a covariance matrix. Either from directly inverting the Hessian (if it's available), or from the approximation PS. Do you really need all 300 parameters? |
Yes, I agree, 32 seconds is perfectly acceptable for a 27 parameter model. However, if 200s would be acceptable is in my opinion dependent on how much time symfit adds to this fit compared to the scipy only fit weighted againts the gain in fitting accuracy or of course time spend programming. For example, in my profiling I find 4 314 861 calls to PS. My physical system has a total of ~800 observables, and we have a total of ~1400 'measurements'. However, not all measurements are independent so the system is underdetermined (aside from being a total pain to fit). Also, not all parameters affect all measurements, ie say parameters 0-4 affect measurement value 1, and parameters 1-6 affect measurement 2, etc etc. So in a way there are many quasi independent fitting problems with some coupling between them. |
My model's |
Symfit was never written for performance :) You can always create your own case-specific subclass of Model or GradientModel where you just hardcode python expressions appropriate for your case. However, I'm not sure it'll be worth the effort: I don't know where the bottle neck is exactly. |
There are some interesting points here. Indeed, For GradientModel we still evaluate the Hessian, but using the jacobian approximation (J^T . J). This is significantly faster than analytically calculating it fully, but still involves calculating the Jacobian analytically. I think the 3 calls to It could be worth trying to optimize that code a bit but this feature was never intended for big systems of equations like this. Computing the Hessians symbolically for such a big system of equations is always going to be expensive. If you need the covariance matrix, I think it is worth looking into how exactly the results from the optimizer are treated. Sometimes the optimizer will return a numerical estimate of the Hessian, Jacobian or the covariance matrix, which we could use. But currently I think we recalculate it because we like to be precise here at As a separate question, is this problem not better solved using the highly experimental matrix_bounds branch? |
I indeed considered this a matrix_bounds jobby, however my problem also has a temporal component with basically a matrix equation per time point. I wasnt sure how to best implement this so I went for the old fashioned way. |
Hmmm, well maybe you can turn it into subproblems using |
I'm having some performance issues with a modestly sized model (37 parameters). The fitting takes a rather long time and profiling revealed that 80% of time time is spend in calling
coveranciance_matrix
/eval_hessian
.symfit_calltree.pdf
I use the standard
LBFGSB
mimimizer and when I replaceModel
withCallablemodel
the total fitting time reduces from 200 seconds to 17 seconds. The fit result is the same.The text was updated successfully, but these errors were encountered: