You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add an optional l2 regularization to the graphical Lasso #12228
The graphical lasso is quite unstable on very ill-conditioned matrix. It is a well known issue that arises from the fact that it is a very optimization problem.
Adding a small amount of l2-regularization helps a lot. On a problem in my lab, it ended being the only way to estimate a sparse inverse covariance. It is actually a simple modification. If people agree, I can try to find the time to contribute this.
I will do it. I already have the code that does it. I just had to write
it today for my research.
Beside, how would you tackle it mathematically? There good way to do it
that is simpler and more robust than the obvious way. It just requires a
small proof that I was planning to attach to the PR.
Sounds good but please include a plot of how this impacts the existing examples in the PR.
Have you exchanged about this l2 penalty with the authors of the glasso package? As far as I understand they do not include l2 penalty either but it would be great to have their opinion on this.
Sounds good but please include a plot of how this impacts the existing examples
in the PR.
Well, if we keep it to a tiny amount by default (ie 1e-10), it will not
change anything.
Have you exchanged about this l2 penalty with the authors of the glasso
package? As far as I understand they do not include l2 penalty either but it
would be great to have their opinion on this.
I don't think that I'll invest the time for this.
In my eyes, the benefits of this modification is that it can make the
solver more stable. We are finding situations where we cannot get the
solver in scikit-learn to converge to SPD matrices. We developed this
variant to get it to converge.
Here is what I suggest: either I can try to find a small synthetic
example where our solver crashes and a little of l2 regularization makes
it converge. If I find this, I do a PR, if not, we just forget it.
WDYT?
Beside, how would you tackle it mathematically? There good way to do it
that is simpler and more robust than the obvious way. It just requires a
small proof that I was planning to attach to the PR. - #12228 (comment)
As far as I understand they do not include l2 penalty either but it would be great to have their opinion on this. - #12228 (comment)
Some information pertinent to the above comments.
You can find more mathematical justification for a graphical elastic net in Allen's dissertation, 2.3.1
My guess is that a graphical elastic net is often used but not been formally implemented due to inertia and there being many other interesting things to work on.
The Friedman algorithm to solve the graphical lasso problem has a known convergence issue that some recent solvers do not. I looked into this a while back here. You might find the examples from the Mazumder paper we used to be a good test case. Note that adding a ridge penalty is not necessary to fix this particular problem convergence problem, though having a well conditioned sample covariance to start with is still useful.
A lot of applications that explicitly study the spectral properties of a covariance matrix could benefit from condition number regularization via nonlinear shrinkage of large and small eigenvalues. I have an internal implementation of condition number regularized MLE that I would be happy to contribute if there is interest in a more general solution. This doesn't distort the eigenstructure as much as Ledoit-Wolf shrinkage.
Four our package http://github.com/metric-learn/metric-learn, we would be really interested in having a more robust Graphical Lasso too, as we use it for the SDML algorithm. Right now, we also have an issue with graphical lasso, but skggm seems to fix it (see PR scikit-learn-contrib/metric-learn#162). Note that in our case we sometimes need to find a sparse (SPD) precision matrix so that its inverse is the closest to a non SPD "covariance-like" matrix (i.e. the "covariance" matrix we pass to graphical lasso can be non SPD). sklearn's graphical lasso seems to not work for such matrices, contrary to skggm (though we need to put have an SPD matrix as initialization which seems normal).
Also, I have noticed that current scikit-learn's graphical lasso does not seem to work even if I put an SPD matrix to reconstruct, whereas it worked with some older versions of scikit-learn.
I don't know if all of this is related to L2 regularization though, but here seemed a good place to add this comment.
I can provide examples if needed, just tell me which one could help: for instance first I could provide a snippet with the new scikit-learn version not working and the old one working ?
Here is a first snippet to show that with an SPD input matrix, the new version of sklearn's graphical_lasso does not seem to work contrary to an older version:
I agree, I just update my comment with skggm's quic (only for the new sklearn's and python version, because I didn't manage to install skggm on the older environment (see skggm/skggm#119). I chose cov_init=np.eye(A.shape[0]) (identity) which is the default for skggm, so that we can compare both (I use identity and not covariance because for the non SPD case I'll use this too (and my "covariance" will be non SPD)) I also added the estimated covariance so that we can see the results. We can see that in the end in the current version even if it says it doesn't converge the estimate is coherent with skggm's one.
Now I'll add some snippets for the non SPD case
It's as if scikit-learn's graphical lasso would estimate a covariance matrix that is similar to the original matrix except the right bottom coeff, which is the same as the upper left one (like in the last case)
We see that scikit-learn estimated covariance is not SPD (which is problematic for SDML's case but for a real covariance case I agree the input should be SPD)
For the example in the code snippet #12228 (comment), sklearn v0.19.2 converges correctly while v0.20rc1 does not (iit returns the same output as the current v0.21.dev0 tried in the above comment).
This holds for Python 2 and 3 and for both solvers (CD and LARS), using numpy 0.15.4.
For the example in the code snippet #12228 (comment), sklearn v0.19.2 converges correctly while v0.20rc1 does not (in the same way as the current v0.21.dev0 tried above.
It might be worth attempting a git bisect on that.
Activity
pulkit6559 commentedon Sep 30, 2018
I would like to work on this issue
GaelVaroquaux commentedon Sep 30, 2018
ogrisel commentedon Oct 1, 2018
Sounds good but please include a plot of how this impacts the existing examples in the PR.
Have you exchanged about this l2 penalty with the authors of the glasso package? As far as I understand they do not include l2 penalty either but it would be great to have their opinion on this.
GaelVaroquaux commentedon Oct 2, 2018
mnarayan commentedon Jan 23, 2019
Some information pertinent to the above comments.
The Friedman algorithm to solve the graphical lasso problem has a known convergence issue that some recent solvers do not. I looked into this a while back here. You might find the examples from the Mazumder paper we used to be a good test case. Note that adding a ridge penalty is not necessary to fix this particular problem convergence problem, though having a well conditioned sample covariance to start with is still useful.
A lot of applications that explicitly study the spectral properties of a covariance matrix could benefit from condition number regularization via nonlinear shrinkage of large and small eigenvalues. I have an internal implementation of condition number regularized MLE that I would be happy to contribute if there is interest in a more general solution. This doesn't distort the eigenstructure as much as Ledoit-Wolf shrinkage.
wdevazelhes commentedon Jan 31, 2019
Four our package http://github.com/metric-learn/metric-learn, we would be really interested in having a more robust Graphical Lasso too, as we use it for the
SDMLalgorithm. Right now, we also have an issue with graphical lasso, but skggm seems to fix it (see PR scikit-learn-contrib/metric-learn#162). Note that in our case we sometimes need to find a sparse (SPD) precision matrix so that its inverse is the closest to a non SPD "covariance-like" matrix (i.e. the "covariance" matrix we pass to graphical lasso can be non SPD). sklearn's graphical lasso seems to not work for such matrices, contrary to skggm (though we need to put have an SPD matrix as initialization which seems normal).Also, I have noticed that current scikit-learn's graphical lasso does not seem to work even if I put an SPD matrix to reconstruct, whereas it worked with some older versions of scikit-learn.
I don't know if all of this is related to L2 regularization though, but here seemed a good place to add this comment.
I can provide examples if needed, just tell me which one could help: for instance first I could provide a snippet with the new scikit-learn version not working and the old one working ?
wdevazelhes commentedon Jan 31, 2019
Here is a first snippet to show that with an
SPDinput matrix, the new version of sklearn's graphical_lasso does not seem to work contrary to an older version:With sklearn's current version (master)
With sklearn's older version:
bellet commentedon Jan 31, 2019
Maybe it is good to add skggm's
quicfor comparison?wdevazelhes commentedon Feb 1, 2019
I agree, I just update my comment with skggm's
quic(only for the new sklearn's and python version, because I didn't manage to install skggm on the older environment (see skggm/skggm#119). I chosecov_init=np.eye(A.shape[0])(identity) which is the default for skggm, so that we can compare both (I use identity and not covariance because for the non SPD case I'll use this too (and my "covariance" will be non SPD)) I also added the estimated covariance so that we can see the results. We can see that in the end in the current version even if it says it doesn't converge the estimate is coherent withskggm's one.Now I'll add some snippets for the non SPD case
bellet commentedon Feb 1, 2019
Actually not, the current sklearn version finds 6 instead of 1 for the lower right value
wdevazelhes commentedon Feb 1, 2019
Ah yes that's right, I looked too fast
wdevazelhes commentedon Feb 1, 2019
Here is an example with a non SPD matrix given as input:
wdevazelhes commentedon Feb 1, 2019
It's as if scikit-learn's graphical lasso would estimate a covariance matrix that is similar to the original matrix except the right bottom coeff, which is the same as the upper left one (like in the last case)
wdevazelhes commentedon Feb 1, 2019
Here is an example a bit different that confirms the above (I just switched the sign on the diagonal):
We see that scikit-learn estimated covariance is not SPD (which is problematic for SDML's case but for a real covariance case I agree the input should be SPD)
wdevazelhes commentedon Feb 1, 2019
Also, in both last cases (non SPD input matrix), old scikit-learn would return:
bellet commentedon Feb 26, 2019
For the example in the code snippet #12228 (comment), sklearn v0.19.2 converges correctly while v0.20rc1 does not (iit returns the same output as the current v0.21.dev0 tried in the above comment).
This holds for Python 2 and 3 and for both solvers (CD and LARS), using numpy 0.15.4.
GaelVaroquaux commentedon Feb 26, 2019