import lmfit
from lmfit import minimize, Minimizer, conf_interval, conf_interval2d
import numpy as np
import scipy as sp
import matplotlib
import matplotlib.pyplot as plt
z = np.array([0.100, 0.170, 0.179, 0.199, 0.270, 0.320, 0.352, 0.400,
0.440, 0.480, 0.570, 0.593,
0.600, 0.680, 0.730, 0.781,
0.875, 0.880, 0.900, 1.037, 1.300, 1.363, 1.430, 1.530,
1.750, 1.965, 2.340, 2.360])
H = np.array([69.0, 83.0, 75.0, 75.0, 77.0, 79.2, 83.0, 95.0, 82.6, 97.0
, 100.3, 104.0, 87.9, 92.0, 97.3, 105.0, 125.0, 90.0, 117.0,
154.0, 168.0, 160.0, 177.0, 140.0, 202.0, 186.5, 222.0,
226.0])
Hin = np.array([12.0, 8.0, 4.0, 5.0, 14.0, 5.6, 14.0, 27.0, 7.8, 62.0,
3.7, 13.0, 6.1, 8.0, 7.0, 12.0, 17.0, 40.0, 23.0,
20.0, 17.0, 33.6, 18.0, 14.0, 40.0, 50.4, 7.0, 16.0])
p = lmfit.Parameters()
p.add_many(('Ho', 67., True, None, None),
('Om', 0.28, True, 0, 0.3),
('Ol', 0.7, True, 0, 1))
def fitCurv(p):
model= p['Ho']*np.sqrt(p['Om']*(1 + z)**3 + p['Ol']
+ (1 - p['Om'] - p['Ol'])*(1 + z)**2)
resids= model - H
weighted = sp.sqrt(resids ** 2 / Hin ** 2)
return weighted
mini = lmfit.Minimizer(fitCurv, p)
result = mini.minimize()
print(lmfit.fit_report(result.params))[[Variables]]
Ho: 66.8695791 +/- 3.727759 (5.57%) (init= 67)
Om: 0.18820806 +/- 0.056660 (30.11%) (init= 0.28)
Ol: 0.48262270 +/- 0.215481 (44.65%) (init= 0.7)
[[Correlations]] (unreported correlations are < 0.100)
C(Ho, Ol) = 0.909
C(Om, Ol) = 0.822
C(Ho, Om) = 0.554
p.add_many(('Ho', 67., True, None, None),
('Om', 0.28, True, 0, 0.3),
('Ol', 0.7, True, 0.6, 0.8))[[Variables]]
Ho: 70.5082253 +/- 0 (0.00%) (init= 67)
Om: 0.23648318 +/- 0 (0.00%) (init= 0.28)
Ol: 0.70000000 +/- 0 (0.00%) (init= 0.7)How can I fix this? The parameters values must be like the reported ones and also I need the parameters variance in order to make the confidence intervals.
Thank you for your time and help.
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+unsubscribe@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/2bd281a0-0da4-41c2-811f-5635771927d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
2. What is `sp.sqrt(resids**2/Hin**2)` supposed to do? You should return the residual or the weighted residual to be minimized in the least-squares sense. I don't think it actually matters much for the result here, but why are you taking the norm here?
--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+unsubscribe@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbrLqdqEqYMfFRrMWAuT7Tc4mYTrgvHqahbyTYV2uTSOzA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/2bd281a0-0da4-41c2-811f-5635771927d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Matt,1. If you know the "right answer", why are you taking data and fitting it to a model? Because I'm learning how to make model fits, and one exercise that would help me with my present work is the one that I describe above, which is data from the Hubble parameter and the model is the LCDM from cosmology. I tried to remake this fitting in order to obtain the values from the matter and energie densities Om and Ol, which 0.72 and 0.28 are the measured values by the telescope Hubble. I started with this because I want to try to get these values but with a more complex model.
2. What is `sp.sqrt(resids**2/Hin**2)` supposed to do? I searched for information about how to include the data error in the fit and I found this page: http://stackoverflow.com/questions/15255928/how-do-i-include-errors-for-my-data-in-the-lmfit-least-squares-miniimization-an they say that `sp.sqrt(resids**2/Hin**2)` should give the correctly weighted fit.