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

Correct behavior of L-curve selection methods #340

Merged
merged 3 commits into from
Jun 23, 2022
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
12 changes: 6 additions & 6 deletions deerlab/selregparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,22 @@ def register_ouputs(optout):

# L-curve minimum-radius method (LR)
if method == 'lr':
Eta = np.log(penalties)
Rho = np.log(residuals)
Eta = np.log(np.asarray(penalties)+1e-20)
Rho = np.log(np.asarray(residuals)+1e-20)
dd = lambda x: (x-np.min(x))/(np.max(x)-np.min(x))
functional = dd(Rho)**2 + dd(Eta)**2

# L-curve maximum-curvature method (LC)
elif method == 'lc':
d1Residual = np.gradient(np.log(residuals))
d1Residual = np.gradient(np.log(np.asarray(residuals)+1e-20))
d2Residual = np.gradient(d1Residual)
d1Penalty = np.gradient(np.log(penalties))
d1Penalty = np.gradient(np.log(np.asarray(penalties)+1e-20))
d2Penalty = np.gradient(d1Penalty)
functional = (d1Residual*d2Penalty - d2Residual*d1Penalty)/(d1Residual**2 + d1Penalty**2)**(3/2)
functional = -functional # Maximize instead of minimize

# Find minimum of the selection functional
alphaOpt = alphaCandidates[np.argmin(functional)]

else:
raise KeyError("Search method not found. Must be either 'brent' or 'grid'.")

Expand Down
2 changes: 1 addition & 1 deletion test/test_selregparam.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_lc_value():
"Check that the value returned by the LC selection method is correct"

loga = get_alpha_from_method('lc')
logaref = -7.900 # Computed with DeerLab-Matlab (0.9.2)
logaref = -1.39

assert abs(1-loga/logaref) < 0.20
#=======================================================================
Expand Down