Skip to content

Commit 59501c6

Browse files
committed
FIX: Rerun bspline fit 3 times, check for extreme values
1 parent e84d838 commit 59501c6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

sdcflows/interfaces/bspline.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,19 @@ def _run_interface(self, runtime):
209209

210210
# Fit the model
211211
model = lm.Ridge(alpha=self.inputs.ridge_alpha, fit_intercept=False)
212-
model.fit(colmat[mask.reshape(-1), :], data[mask])
212+
for attempt in range(3):
213+
model.fit(colmat[mask.reshape(-1), :], data[mask])
214+
extreme = np.abs(model.coef_).max()
215+
LOGGER.debug(f"Model fit attempt {attempt}: max(|coeffs|) = {extreme}")
216+
# Normal values seem to be ~1e2, bad ~1e8. May want to tweak this if
217+
# these distributions are wider than I think.
218+
if extreme < 1e4:
219+
break
220+
else:
221+
raise RuntimeError(
222+
f"Spline fit of input file {self.inputs.in_data} failed. "
223+
f"Extreme value {extreme:.2e} detected in spline coefficients."
224+
)
213225

214226
# Store coefficients
215227
index = 0

0 commit comments

Comments
 (0)