def template_admm_vs_ppdna(p=50, K=3, N=1000, reg="GGL"): M = 5 # M should be divisor of p if reg == 'GGL': Sigma, Theta = group_power_network(p, K, M) elif reg == 'FGL': Sigma, Theta = time_varying_power_network(p, K, M) S, samples = sample_covariance_matrix(Sigma, N) lambda1 = 0.05 lambda2 = 0.01 Omega_0 = get_K_identity(K, p) sol, info = ADMM_MGL(S, lambda1, lambda2, reg, Omega_0, stopping_criterion='kkt', tol=1e-6, rtol=1e-5, verbose=True, latent=False) sol2, info2 = warmPPDNA(S, lambda1, lambda2, reg, Omega_0, eps=1e-6, verbose=False, measure=True) sol3, info3 = PPDNA(S, lambda1, lambda2, reg, Omega_0, eps_ppdna=1e-6, verbose=True, measure=True) assert_array_almost_equal(sol['Theta'], sol2['Theta'], 2) assert_array_almost_equal(sol2['Theta'], sol3['Theta'], 2) return
def template_ADMM_MGL(p=100, K=5, N=1000, reg='GGL', latent=False): """ template for test for ADMM MGL solver with conforming variables """ M = 10 # M should be divisor of p if reg == 'GGL': Sigma, Theta = group_power_network(p, K, M) elif reg == 'FGL': Sigma, Theta = time_varying_power_network(p, K, M) S, samples = sample_covariance_matrix(Sigma, N) lambda1 = 0.05 lambda2 = 0.01 Omega_0 = get_K_identity(K, p) sol, info = ADMM_MGL(S, lambda1, lambda2, reg, Omega_0, tol=1e-5, rtol=1e-5, verbose=True, measure=True, latent=latent, mu1=0.01) assert info['status'] == 'optimal' _, info2 = ADMM_MGL(S, lambda1, lambda2, reg, Omega_0, tol=1e-20, rtol=1e-20, max_iter=2, latent=latent, mu1=0.01) assert info2['status'] == 'max iterations reached' return
def test_FGL_latent(): Sigma, Theta = time_varying_power_network(p, K, M) S, samples = sample_covariance_matrix(Sigma, N) template_problem_MGL(S, N, reg = 'FGL', latent = True) return
from gglasso.solver.latent_admm_solver import latent_ADMM_GGL from gglasso.helper.data_generation import time_varying_power_network, group_power_network, sample_covariance_matrix from gglasso.helper.experiment_helper import get_K_identity from gglasso.helper.model_selection import grid_search, single_range_search p = 100 K = 5 N = 1000 M = 2 reg = 'GGL' if reg == 'GGL': Sigma, Theta = group_power_network(p, K, M) elif reg == 'FGL': Sigma, Theta = time_varying_power_network(p, K, M) #np.linalg.norm(np.eye(p) - Sigma@Theta) S, samples = sample_covariance_matrix(Sigma, N) #S = get_K_identity(K,p) lambda1 = 0.05 lambda2 = 0.05 L = np.logspace(-1, -3, 5) #%% grid_search(ADMM_MGL, S, N, p, reg, L, method='eBIC', l2=L) est_uniform, est_indv, range_stats = single_range_search(S, L,
from gglasso.solver.admm_solver import ADMM_MGL from gglasso.helper.data_generation import time_varying_power_network, sample_covariance_matrix from gglasso.helper.experiment_helper import lambda_grid, discovery_rate, error from gglasso.helper.utils import get_K_identity from gglasso.helper.experiment_helper import plot_evolution, plot_deviation, surface_plot, single_heatmap_animation from gglasso.helper.model_selection import aic, ebic p = 100 K = 10 N = 5000 M = 5 L = int(p / M) reg = 'FGL' Sigma, Theta = time_varying_power_network(p, K, M, scale=False, nxseed=2340) S, sample = sample_covariance_matrix(Sigma, N) results = {} results['truth'] = {'Theta': Theta} #%% # Animate precision matrix over time # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # colored squares represent non-zero entries # anim = single_heatmap_animation(Theta) # %%