This commit is contained in:
Simon Kuberski 2021-11-15 16:46:22 +01:00
parent 5a347e0506
commit 9839eb7f0c

View file

@ -110,7 +110,7 @@ def least_squares(x, y, func, priors=None, silent=False, **kwargs):
This can take a while as the full correlation matrix This can take a while as the full correlation matrix
has to be calculated (default False). has to be calculated (default False).
correlated_fit : bool correlated_fit : bool
If true, use the full correlation matrix in the definition of the chisquare If true, use the full correlation matrix in the definition of the chisquare
(only works for prior==None and when no method is given, at the moment). (only works for prior==None and when no method is given, at the moment).
const_par : list, optional const_par : list, optional
List of N Obs that are used to constrain the last N fit parameters of func. List of N Obs that are used to constrain the last N fit parameters of func.
@ -181,7 +181,7 @@ def total_least_squares(x, y, func, silent=False, **kwargs):
const_par = kwargs['const_par'] const_par = kwargs['const_par']
if isinstance(const_par, Obs): if isinstance(const_par, Obs):
const_par = [const_par] const_par = [const_par]
def func(p, x): def func(p, x):
return func_aug(np.concatenate((p, [o.value for o in const_par])), x) return func_aug(np.concatenate((p, [o.value for o in const_par])), x)
else: else:
@ -511,23 +511,23 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
chol = np.linalg.cholesky(corr) chol = np.linalg.cholesky(corr)
chol_inv = np.linalg.inv(chol) chol_inv = np.linalg.inv(chol)
chol_inv = np.dot(chol_inv, covdiag) chol_inv = np.dot(chol_inv, covdiag)
def chisqfunc(p): def chisqfunc(p):
model = func(p, x) model = func(p, x)
chisq = anp.sum(anp.dot(chol_inv, (y_f - model)) ** 2) chisq = anp.sum(anp.dot(chol_inv, (y_f - model)) ** 2)
return chisq return chisq
def chisqfunc_aug(p): def chisqfunc_aug(p):
model = func_aug(np.concatenate((p, [o.value for o in const_par])), x) model = func_aug(np.concatenate((p, [o.value for o in const_par])), x)
chisq = anp.sum(anp.dot(chol_inv, (y_f - model)) ** 2) chisq = anp.sum(anp.dot(chol_inv, (y_f - model)) ** 2)
return chisq return chisq
else: else:
def chisqfunc(p): def chisqfunc(p):
model = func(p, x) model = func(p, x)
chisq = anp.sum(((y_f - model) / dy_f) ** 2) chisq = anp.sum(((y_f - model) / dy_f) ** 2)
return chisq return chisq
def chisqfunc_aug(p): def chisqfunc_aug(p):
model = func_aug(np.concatenate((p, [o.value for o in const_par])), x) model = func_aug(np.concatenate((p, [o.value for o in const_par])), x)
chisq = anp.sum(((y_f - model) / dy_f) ** 2) chisq = anp.sum(((y_f - model) / dy_f) ** 2)
@ -557,7 +557,7 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
model = func(p, x) model = func(p, x)
chisq = anp.dot(chol_inv, (y_f - model)) chisq = anp.dot(chol_inv, (y_f - model))
return chisq return chisq
else: else:
def chisqfunc_residuals(p): def chisqfunc_residuals(p):
model = func(p, x) model = func(p, x)
@ -606,7 +606,7 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
model = func_aug(d[:n_parms_aug], x) model = func_aug(d[:n_parms_aug], x)
chisq = anp.sum(anp.dot(chol_inv, (d[n_parms_aug:] - model)) ** 2) chisq = anp.sum(anp.dot(chol_inv, (d[n_parms_aug:] - model)) ** 2)
return chisq return chisq
else: else:
def chisqfunc_compact(d): def chisqfunc_compact(d):
model = func_aug(d[:n_parms_aug], x) model = func_aug(d[:n_parms_aug], x)