Hi,And first thanks for your package lmfit which is a very nice lib to make easier fitting stuff in Python !I am trying to fit model (here 2D gaussian but it could something else) to images in order to retrieve position of filaments (very short such as gaussian or very long which needs another model I won't discuss here).Trying to use lmfit I have two questions.I don't understand why when I am trying to fit a simulated 2D gaussian, the fit does not converge if my initial value are not very close to the solution...
While my parameters are bounded inside the image and so the algorithm could easily visit all the set of parameters (at least for x0 and y0).
I also tried with different fitting method without success (some methods does not work because they need a Jacobian... but I don't know how to give that to the model).
[[Model]]
Model(func)
[[Fit Statistics]]
# function evals = 106
# data points = 2500
# variables = 4
chi-square = 1194887.925
reduced chi-square = 478.721
Akaike info crit = 15435.796
Bayesian info crit = 15459.092
[[Variables]]
x0: 1.3086e-08 +/- 3.108836 (23756449250.30%) (init= 25)
y0: 9.1276e-05 +/- 4.532151 (4965345.44%) (init= 25)
sigma: 85.3817857 +/- 7.256131 (8.50%) (init= 25)
H: 116.364443 +/- 1.454531 (1.25%) (init= 195.8755)
[[Correlations]] (unreported correlations are < 0.100)
C(y0, sigma) = -0.883
C(x0, sigma) = -0.870
C(x0, y0) = 0.766
C(y0, H) = -0.757
C(x0, H) = -0.751
C(sigma, H) = 0.571
[[Model]]
Model(func)
[[Fit Statistics]]
# function evals = 85
# data points = 2500
# variables = 4
chi-square = 70446.751
reduced chi-square = 28.224
Akaike info crit = 8358.419
Bayesian info crit = 8381.715
[[Variables]]
x0: 5.00456894 +/- 0.021736 (0.43%) (init= 25)
y0: 5.00448600 +/- 0.021736 (0.43%) (init= 25)
sigma: 3.12933197 +/- 0.016463 (0.53%) (init= 25)
H: 201.230519 +/- 1.395864 (0.69%) (init= 196.9911)
[[Correlations]] (unreported correlations are < 0.100)
C(sigma, H) = -0.723 Hi Matt and thank you for your answer,Sorry I should have explain what I want to do more precisely.I know peak finding algorithm exists but it's not what I want to do here. Gaussian model was an example bu the idea is to detect more complex objet such as filaments in images. To do that I have some models describing gaussian wall, stretched peaks, filament tips, etc. I am trying to implement a method from this paper http://www.cell.com/biophysj/fulltext/S0006-3495(11)00467-X in Python (the original implementation is in Matlab). In the paper they use a fitting method (leastsq).
With the simulated data and the initial guess at (25, 25, 25) works nicely. But when I apply it to the real data, it fails. Note that x0 and y0 is indeed moving to the right direction but the sigma always stay at a very high value.
Coming back to simulated data with (25, 25, 25), I found that the fit is not robust to noise (even small), for example adding `image += np.random.poisson(50, image.shape)` prevents the fit to work. Same remark as with the real data, x0 and y0 is moving the right direction but the sigma value never decrease. So I guess that simulated data + noise acts the same as my real data.
What criteria make the method to stop doing more iterations ? Because each time the fit is ending pretty close to the correct value and I would hope that some more iterations would allow it to find the correct x0 and y0 and give it time to decrease the sigma value.