def assert_full_output(method): t = np.linspace(0, 5, 80) r = np.linspace(2, 5, 80) P = dd_gauss(r, 3, 0.4) K = dipolarkernel(t, r) L = regoperator(r, 2) V = K @ P alpha, alphas_evaled, functional, residuals, penalties = selregparam( V, K, cvxnnls, method='aic', algorithm=method, full_output=True, regop=L) errors = [] if np.size(alpha) != 1: errors.append("alphaopt is not a scalar") if len(functional) != len(alphas_evaled): errors.append( "The number of elements of functional values and evaluated alphas are different." ) if len(residuals) != len(penalties): errors.append( "The number of elements of evluated residuals and penalties are different" ) if not alpha in alphas_evaled: errors.append("The optimal alpha is not part of the evaluated alphas") assert not errors, f"Errors occured:\n{chr(10).join(errors)}"
def test_algorithms(): #======================================================================= "Check that the value returned by the the grid and Brent algorithms coincide" t = np.linspace(0, 5, 80) r = np.linspace(2, 5, 80) P = dd_gauss(r, 3, 0.2) K = dipolarkernel(t, r) L = regoperator(r, 2) V = K @ P + whitegaussnoise(t, 0.02, seed=1) alpha_grid = selregparam(V, K, cvxnnls, method='aic', algorithm='grid', regop=L) alpha_brent = selregparam(V, K, cvxnnls, method='aic', algorithm='brent', regop=L) assert abs(1 - alpha_grid / alpha_brent) < 0.15
def get_alpha_from_method(method): t = np.linspace(0, 5, 500) r = np.linspace(2, 5, 80) P = dd_gauss(r, 3.0, 0.16986436005760383) K = dipolarkernel(t, r) L = regoperator(r, 2, includeedges=True) V = K @ P alpha = selregparam(V, K, cvxnnls, method=method, noiselvl=0, regop=L) return np.log10(alpha)
def test_confinter_tikh(): #============================================================ "Check that the confidence intervals are correctly computed using Tikhonov regularization" t = np.linspace(-2, 4, 300) r = np.linspace(2, 6, 100) P = dd_gauss(r, 3, 0.2) K = dipolarkernel(t, r) V = K @ P fit = snlls(V, K, lbl=np.zeros_like(r)) assert_confidence_intervals(fit.paramUncert, fit.param)