Skip to content
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

snlls: Fix violation of boundaries due to float-point round-off errors #188

Merged
merged 5 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions deerlab/snlls.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def snlls(y, Amodel, par0, lb=None, ub=None, lbl=None, ubl=None, nnlsSolver='cvx
elif nnlsSolver == 'cvx':
linSolver = lambda AtA, Aty: cvxnnls(AtA, Aty, tol=lin_tol, maxiter=lin_maxiter)
parseResult = lambda result: result

# Ensure correct formatting and shield against float-point errors
validateResult = lambda result: np.maximum(lbl,np.minimum(ubl,np.atleast_1d(result)))
# ----------------------------------------------------------

# Containers for alpha-update checks
Expand All @@ -319,9 +322,9 @@ def linear_problem(A,optimize_alpha,alpha):

# Solve the linear least-squares problem
result = linSolver(AtA, Aty)
linfit = parseResult(result)
linfit = np.atleast_1d(linfit)
result = parseResult(result)
linfit = validateResult(result)

return linfit, alpha
#===========================================================================

Expand Down Expand Up @@ -566,4 +569,3 @@ def _plot(subsets,y,yfit,show):
plt.close()
return fig
# ===========================================================================================

2 changes: 1 addition & 1 deletion deerlab/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def Jacobian(fcn, x0, lb, ub):

"""
J = opt._numdiff.approx_derivative(fcn,x0,method='2-point',bounds=(lb,ub))
J = np.atleast_2d(J)
J = np.atleast_2d(J)
return J
#===============================================================================

Expand Down