Skip to content
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

Performance "regression" in 2.0.0rc2 #326

Open
toni-neurosc opened this issue Jun 17, 2024 · 1 comment
Open

Performance "regression" in 2.0.0rc2 #326

toni-neurosc opened this issue Jun 17, 2024 · 1 comment

Comments

@toni-neurosc
Copy link

toni-neurosc commented Jun 17, 2024

Hi, first of all, thank you very much for developing and maintaining this package. I'm one of the contributors of py_neuromodulation, a Python tool for feature extraction from neurophysiology recordings. We include FOOOF as one of the available features that we can calculate during data analysis, and recently I came across the new renamed version SpecParam. Although we don't have a strong reason to update I wanted to give the new version a try, since the numerical methods used by FOOOF are computationally expensive and difficult to run in real-time when we want to run our analysis online.

However when I replaced the FOOOF class with SpectralModel, I noticed I was getting different output values and also that it was running 2x as slow as FOOOF. I started digging and figured out this only happens with the newer release candidate 2.0.0rc2, which is the version that pip is currently installing, while with rc1 I get the exact same results as with the FOOOF package v1.1.

It seems that the reason for the change in fitted parameters and speed is that in rc2 SciPy's curve_fit is now being called with the default xtol, ftol and gtol parameters, as opposed to the 1E-5 set in #299 . Once I add back the tolerance to curve_fit, the results and the computation time come much closer, and once the jacobian_gauss is added back, the results are identical (the remaining missing parameter check_finite=False makes no difference)

Is there a reason for this change? I understand that there might be a concern with the precision of the model fit, but the doubling in the computation time is a bit expensive in use-cases like ours when we would want to be able to output real-time feature calculations. Of course, one could argue that for online analysis spectral parametrization is just not a viable metric, but I was hoping that perhaps with future performance increases it would come closer to real-time.

So, to sum up:

  • What is the rationale behind dropping the looser tolerance for curve_fit. Were the previous tolerance values too inacurate?
  • Could we get a parameter in the SpectralModel class to set the curve_fit tolerance value?

EDIT: one more question

  • Why was the Gaussian function jacobian dropped? It reduces computation time by 10% in my system, seems reasonable to keep it as a parameter to curve_fit
@TomDonoghue
Copy link
Member

TomDonoghue commented Jun 29, 2024

hey @toni-neurosc - thanks for detailed check in here, and sorry for a slow (and currently a bit limited) answer as I'm currently traveling.

I believe what has happened here is that you have discovered an accidental mistake in me merging things together as work for specparam2.0 became spread across multiple branches! At some point I had a bit of a complicated merge & refactor and I was pretty sure I didn't miss anything, but you are right that current rc2 is missing some changes from #299, and that is not on purpose! I will make sure it all gets merged back in - though it might be another week or two before I get to it - I realize now I need to do a bit of an audit across the branches and check through and figure out where the mistake is and double check everything does come back to merge all together, with all the updates.

Apologies for the confusion here, and thank you for the deep dive that helped figure this out! I'll follow up on this issue once I get the chance to work through and get things fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants