mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 12:03:42 +02:00
fix: index of num diff jacobian in least squares fit corrected.
This commit is contained in:
parent
ee4149e498
commit
99e130d33c
1 changed files with 10 additions and 1 deletions
|
@ -416,7 +416,10 @@ def _prior_fit(x, y, func, priors, silent=False, **kwargs):
|
||||||
if not m.fmin.is_valid:
|
if not m.fmin.is_valid:
|
||||||
raise Exception('The minimization procedure did not converge.')
|
raise Exception('The minimization procedure did not converge.')
|
||||||
|
|
||||||
hess_inv = np.linalg.pinv(jacobian(jacobian(chisqfunc))(params))
|
hess = jacobian(jacobian(chisqfunc))(params)
|
||||||
|
if kwargs.get('num_grad') is True:
|
||||||
|
hess = hess[0]
|
||||||
|
hess_inv = np.linalg.pinv(hess)
|
||||||
|
|
||||||
def chisqfunc_compact(d):
|
def chisqfunc_compact(d):
|
||||||
model = func(d[:n_parms], x)
|
model = func(d[:n_parms], x)
|
||||||
|
@ -424,6 +427,8 @@ def _prior_fit(x, y, func, priors, silent=False, **kwargs):
|
||||||
return chisq
|
return chisq
|
||||||
|
|
||||||
jac_jac = jacobian(jacobian(chisqfunc_compact))(np.concatenate((params, y_f, p_f)))
|
jac_jac = jacobian(jacobian(chisqfunc_compact))(np.concatenate((params, y_f, p_f)))
|
||||||
|
if kwargs.get('num_grad') is True:
|
||||||
|
jac_jac = jac_jac[0]
|
||||||
|
|
||||||
deriv = -hess_inv @ jac_jac[:n_parms, n_parms:]
|
deriv = -hess_inv @ jac_jac[:n_parms, n_parms:]
|
||||||
|
|
||||||
|
@ -591,6 +596,8 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
||||||
hess = jacobian(jacobian(chisqfunc))(fitp)
|
hess = jacobian(jacobian(chisqfunc))(fitp)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
raise Exception("It is required to use autograd.numpy instead of numpy within fit functions, see the documentation for details.") from None
|
raise Exception("It is required to use autograd.numpy instead of numpy within fit functions, see the documentation for details.") from None
|
||||||
|
if kwargs.get('num_grad') is True:
|
||||||
|
hess = hess[0]
|
||||||
|
|
||||||
if kwargs.get('correlated_fit') is True:
|
if kwargs.get('correlated_fit') is True:
|
||||||
def chisqfunc_compact(d):
|
def chisqfunc_compact(d):
|
||||||
|
@ -605,6 +612,8 @@ def _standard_fit(x, y, func, silent=False, **kwargs):
|
||||||
return chisq
|
return chisq
|
||||||
|
|
||||||
jac_jac = jacobian(jacobian(chisqfunc_compact))(np.concatenate((fitp, y_f)))
|
jac_jac = jacobian(jacobian(chisqfunc_compact))(np.concatenate((fitp, y_f)))
|
||||||
|
if kwargs.get('num_grad') is True:
|
||||||
|
jac_jac = jac_jac[0]
|
||||||
|
|
||||||
# Compute hess^{-1} @ jac_jac[:n_parms, n_parms:] using LAPACK dgesv
|
# Compute hess^{-1} @ jac_jac[:n_parms, n_parms:] using LAPACK dgesv
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue