Skip to content

Commit

Permalink
Merge pull request #366 from effigies/fix/rerun-bspline
Browse files Browse the repository at this point in the history
FIX: Use lsqr solver for spline fit, rerun on extreme values
  • Loading branch information
effigies authored Jun 8, 2023
2 parents d3acae1 + bd8d9fd commit 34ae6f7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions sdcflows/interfaces/bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,20 @@ def _run_interface(self, runtime):
)

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

# Store coefficients
index = 0
Expand Down

0 comments on commit 34ae6f7

Please sign in to comment.