Skip to content

FIX: Use lsqr solver for spline fit, rerun on extreme values #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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