Skip to content

Commit 34ae6f7

Browse files
authored
Merge pull request #366 from effigies/fix/rerun-bspline
FIX: Use lsqr solver for spline fit, rerun on extreme values
2 parents d3acae1 + bd8d9fd commit 34ae6f7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

sdcflows/interfaces/bspline.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,20 @@ def _run_interface(self, runtime):
208208
)
209209

210210
# Fit the model
211-
model = lm.Ridge(alpha=self.inputs.ridge_alpha, fit_intercept=False)
212-
model.fit(colmat[mask.reshape(-1), :], data[mask])
211+
model = lm.Ridge(alpha=self.inputs.ridge_alpha, fit_intercept=False, solver='lsqr')
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)