Last active
June 22, 2016 23:12
-
-
Save rahuln/7d2c24cbef007b9f09ff8f9934df9b8f to your computer and use it in GitHub Desktop.
Spearmint code for GLASSO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "language" : "PYTHON", | |
| "main-file" : "glasso.py", | |
| "experiment-name" : "glasso-test", | |
| "likelihood" : "NOISELESS", | |
| "variables" : { | |
| "alpha" : { | |
| "type" : "FLOAT", | |
| "size" : 1, | |
| "min" : 0.012, | |
| "max" : 0.014 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from sklearn.covariance import GraphLasso, GraphLassoCV | |
| def glasso(alpha): | |
| train_cov = np.load('train.npy') | |
| validation_cov = np.load('validation.npy') | |
| graphlasso = GraphLasso(alpha=alpha) | |
| graphlasso.fit(train_cov) | |
| log_likelihood = graphlasso.score(validation_cov) | |
| print "negative log-likelhood: %.5f" % -log_likelihood | |
| return -log_likelihood | |
| def main(job_id, params): | |
| return glasso(params['alpha']) | |
| def glasso_cv(alphas=None, amin=-10, amax=-1, gridsize=100): | |
| train_cov = np.load('train.npy') | |
| validation_cov = np.load('validation.npy') | |
| if alphas is None: | |
| alphas = list(np.logspace(amin, amax, gridsize)) | |
| graphlassocv = GraphLassoCV(alphas=alphas) | |
| graphlassocv.fit(train_cov) | |
| log_likelihood = graphlassocv.score(validation_cov) | |
| print "negative log-likelihood: %.5f" % -log_likelihood | |
| return -log_likelihood, graphlassocv | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment