Note
Click here to download the full example code
Convergence Failure of Glasso¶
Demonstration of cases where graph_lasso fails to converge and quic succeeds.
“The graphical lasso: New Insights and alternatives”, by Mazumder & Hastie 2012. https://web.stanford.edu/~hastie/Papers/glassoinsights.pdf
import sys
sys.path.append("..")
sys.path.append("../inverse_covariance")
from sklearn.covariance import graph_lasso
from inverse_covariance import quic
import numpy as np
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/skggm/envs/latest/lib/python2.7/site-packages/sphinx_gallery/gen_rst.py", line 480, in _memory_usage
out = func()
File "/home/docs/checkouts/readthedocs.org/user_builds/skggm/envs/latest/lib/python2.7/site-packages/sphinx_gallery/gen_rst.py", line 465, in __call__
exec(self.code, self.globals)
File "/home/docs/checkouts/readthedocs.org/user_builds/skggm/checkouts/latest/examples/convergence_comparison.py", line 18, in <module>
from inverse_covariance import quic
File "/home/docs/checkouts/readthedocs.org/user_builds/skggm/checkouts/latest/inverse_covariance/__init__.py", line 3, in <module>
from .quic_graph_lasso import (
File "/home/docs/checkouts/readthedocs.org/user_builds/skggm/checkouts/latest/inverse_covariance/quic_graph_lasso.py", line 12, in <module>
from joblib import Parallel, delayed
ImportError: No module named joblib
Example 1 graph_lasso fails to converge at lam = .009 * np.max(np.abs(Shat))
X = np.loadtxt("data/Mazumder_example1.txt", delimiter=",")
Shat = np.cov(X, rowvar=0)
try:
graph_lasso(Shat, alpha=.004)
except FloatingPointError as e:
print("{0}".format(e))
vals = quic(Shat, .004)
Example 2 graph_lasso fails to converge at lam = .009 * np.max(np.abs(Shat))
X = np.loadtxt("data/Mazumder_example2.txt", delimiter=",")
Shat = np.cov(X, rowvar=0)
try:
graph_lasso(Shat, alpha=.02)
except FloatingPointError as e:
print("{0}".format(e))
vals = quic(Shat, .02)
Total running time of the script: ( 0 minutes 0.290 seconds)