def adaptive_model_average(X, penalization, method):
    """Run ModelAverage in default mode (QuicGraphicalLassoCV) to obtain proportion
    matrix.

    NOTE:  Only method = 'binary' really makes sense in this case.
    """
    n_trials = 100
    print("Adaptive ModelAverage with:")
    print("   estimator: QuicGraphicalLasso (default)")
    print("   n_trials: {}".format(n_trials))
    print("   penalization: {}".format(penalization))
    print("   adaptive-method: {}".format(method))

    # if penalization is random, first find a decent scalar lam_ to build
    # random perturbation matrix around. lam doesn't matter for fully-random.
    lam = 0.5
    if penalization == "random":
        cv_model = QuicGraphicalLassoCV(
            cv=2, n_refinements=6, n_jobs=1, init_method="cov", score_metric=metric
        )
        cv_model.fit(X)
        lam = cv_model.lam_
        print("   lam: {}".format(lam))

    model = AdaptiveGraphicalLasso(
        estimator=ModelAverage(
            n_trials=n_trials, penalization=penalization, lam=lam, n_jobs=1
        ),
        method=method,
    )
    model.fit(X)
    lam_norm_ = np.linalg.norm(model.estimator_.lam_)
    print("   ||lam_||_2: {}".format(lam_norm_))
    return model.estimator_.covariance_, model.estimator_.precision_, lam_norm_
def adaptive_model_average ( X , penalization , method ) : n_trials = 100 print ( "Adaptive ModelAverage with:" ) print ( "   estimator: QuicGraphicalLasso (default)" ) print ( "   n_trials: {}" . format ( n_trials ) ) print ( "   penalization: {}" . format ( penalization ) ) print ( "   adaptive-method: {}" . format ( method ) ) lam = 0.5 if penalization == "random" : cv_model = QuicGraphicalLassoCV ( cv = 2 , n_refinements = 6 , n_jobs = 1 , init_method = "cov" , score_metric = metric ) cv_model . fit ( X ) lam = cv_model . lam_ print ( "   lam: {}" . format ( lam ) ) model = AdaptiveGraphicalLasso ( estimator = ModelAverage ( n_trials = n_trials , penalization = penalization , lam = lam , n_jobs = 1 ) , method = method , ) model . fit ( X ) lam_norm_ = np . linalg . norm ( model . estimator_ . lam_ ) print ( "   ||lam_||_2: {}" . format ( lam_norm_ ) ) return model . estimator_ . covariance_ , model . estimator_ . precision_ , lam_norm_
Run ModelAverage in default mode (QuicGraphicalLassoCV) to obtain proportion
    matrix.

    NOTE:  Only method = 'binary' really makes sense in this case.