79284822

Date: 2024-12-16 13:27:01
Score: 2
Natty:
Report link

Without having the data at hand I will have to speculate a bit but from experience I would guess that you have one of the following problems

1. Misfit Model

I believe this to be the most likely. This would mean that your data just isn't a sine wave and this is in fact the best fit. Do you have any theory to suggest that your data should follow a sine wave? (Not all periodic functions are sine waves. I have seen a lot of undergrads make mistakes like this.)

2. Local Minimum

Scipy curve_fit uses the scipy.optimize.minimize function, which is a local minimizer. If your X² is non convex in parameter space you may be getting stuck in a local minimum. You can try to measure your systemic bias separately and set it as a constraint. (Or just replace C with the number you measure) Calculate the reduced Chi Squared for both and select the better seloution. Alternatively you can define your own loss functon and run a global search algorithm like scipy.optimize.dual_annealing(). (I have implemented this for distribution fitting in my fitting_toolkit repository)

3. Unstable Loss function

I do not think this is the issue. I have never had this problem with sin-wave, however I will add it for completeness. scipy.optimize.curvefit uses least squares fitting which is notoriously unstable for non polynomial models. In that case you may want to use another optimization like Maximum Likelyhood Estimation

Reasons:
  • RegEx Blacklisted phrase (2.5): Do you have any
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: David K.