コード例 #1
0
ファイル: estimator_suite.py プロジェクト: medic20/skggm
def quic_graph_lasso_ebic(X, gamma=0):
    '''Run QuicGraphLassoEBIC with gamma.

    QuicGraphLassoEBIC is a convenience class.  Results should be identical to
    those obtained via quic_graph_lasso_ebic_manual.
    '''
    print 'QuicGraphLassoEBIC with:'
    print '   mode: path'
    print '   gamma: {}'.format(gamma)
    model = QuicGraphLassoEBIC(lam=1.0, init_method='cov', gamma=gamma)
    model.fit(X)
    print '   len(path lams): {}'.format(len(model.path_))
    print '   lam_scale_: {}'.format(model.lam_scale_)
    print '   lam_: {}'.format(model.lam_)
    return model.covariance_, model.precision_, model.lam_
コード例 #2
0
    def test_integration_quic_graph_lasso_ebic(self, params_in, expected):
        '''
        Just tests inputs/outputs (not validity of result).
        '''
        X = datasets.load_diabetes().data
        ic = QuicGraphLassoEBIC(**params_in)
        ic.fit(X)

        result_vec = [
            np.linalg.norm(ic.covariance_),
            np.linalg.norm(ic.precision_),
        ]
        if isinstance(ic.lam_, float):
            result_vec.append(ic.lam_)
        elif isinstance(ic.lam_, np.ndarray):
            assert ic.lam_.shape == params_in['lam'].shape

        print result_vec
        assert_allclose(expected, result_vec, rtol=1e-1)
コード例 #3
0
#%% 
# run analysis on all subjects
# build timeseries for first scan (before)
totalSub_series_1 = timeSeries(func_files=fileList(totalSub,'1'), confound_files=confList(totalSub, '1'))
totalSub_series_2 = timeSeries(func_files=fileList(totalSub,'2'), confound_files=confList(totalSub, '2'))
# In[skggm]:
# run EBIC LASSO on each subject
from inverse_covariance import QuicGraphLassoEBIC
# call estimator EBIC
estimator = QuicGraphLassoEBIC(init_method="cov", verbose=1)
# create emtpy array
ebicMat = []
ebicMat2 = []
# run loop over timeseries and create precision matrix for each subject, append to a list of matrices
for i in totalSub_series_1:
    estimator.fit(i)
    ebicMat.append(-estimator.precision_)
    

for i in totalSub_series_2:
    estimator.fit(i)
    ebicMat2.append(-estimator.precision_)

ket1_forLASSO.shape
#%%
import matplotlib.pyplot as plt
%matplotlib qt
# Display the sparse inverse covariance
plt.figure(figsize=(7.5, 7.5))
plt.imshow(
    np.triu(-estimator.precision_, 1), interpolation="nearest", cmap=plt.cm.RdBu_r