diff --git a/deerlab/selregparam.py b/deerlab/selregparam.py index 1558a606..9a63d965 100644 --- a/deerlab/selregparam.py +++ b/deerlab/selregparam.py @@ -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'.") diff --git a/test/test_selregparam.py b/test/test_selregparam.py index 64099eeb..ceaeb173 100644 --- a/test/test_selregparam.py +++ b/test/test_selregparam.py @@ -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 #=======================================================================