Ensure fitresult.covar is not None before processing#104
Conversation
Add check for non-null covariance matrix in fit result
|
Thanks for reporting this. What happens right now when the covar cannot be computed? Does it bomb or does it simply not compute stderr. |
|
It now just crashes on See below: Cell In[3], [line 53](vscode-notebook-cell:?execution_count=3&line=53)
52 cal.series(name="obs", x=x, y=y, t=t_obs, h=h_obs, layer=0)
---> [53](vscode-notebook-cell:?execution_count=3&line=53) cal.fit(report=False)
File ~.venv/lib/python3.13/site-packages/timflow/transient/fit.py:391, in Calibrate.fit(self, report, printdot, **kwargs)
388 def fit(self, report=False, printdot=True, **kwargs):
389 # current default fitting routine is lmfit
390 # return self.fit_least_squares(report) # does not support bounds by default
--> [391](.venv/lib/python3.13/site-packages/timflow/transient/fit.py:391) return self.fit_lmfit(report, printdot, **kwargs)
File ~.venv/lib/python3.13/site-packages/timflow/transient/fit.py:348, in Calibrate.fit_lmfit(self, report, printdot, **kwargs)
344 self.parameters.loc[name, "optimal"] = self.fitresult.params.valuesdict()[
345 name
346 ]
347 if hasattr(self.fitresult, "covar"):
--> [348](.venv/lib/python3.13/site-packages/timflow/transient/fit.py:348) self.parameters["std"] = np.sqrt(np.diag(self.fitresult.covar))
349 self.parameters["perc_std"] = (
350 100 * self.parameters["std"] / np.abs(self.parameters["optimal"])
351 )
352 else:
File ~/.venv/lib/python3.13/site-packages/numpy/lib/_twodim_base_impl.py:328, in diag(v, k)
326 return diagonal(v, k)
327 else:
--> [328](~.venv/lib/python3.13/site-packages/numpy/lib/_twodim_base_impl.py:328) raise ValueError("Input must be 1- or 2-d.")
ValueError: Input must be 1- or 2-d. |
|
Well that is no good. So your fix is probably needed until we move forward on the stderr issue. |
|
I removed the parameter uncertainty stuff in the unified calibration class. We could consider just removing the computation of that stuff here as well? Otherwise the proposed fix seems fine for now. |
|
This PR is replaced by #105. |
I'm running into an issue where the
fitresult.covaris None.