def test_gaussian(n=200, p=30, burnin=2000, ndraw=8000,
                  compute_interval=False,
                  s=6):

    X, y, beta, lasso_active, sigma = lasso_instance(n=n, 
                                                     p=p)
    n, p = X.shape

    lam = sigma * np.mean(np.fabs(np.dot(X.T, np.random.standard_normal((n, 10000)))).max(0))

    L = randomized_lasso(y, X, lam, (True, 0.4 * np.diag(np.sqrt(np.diag(np.dot(X.T, X))))),
                         sandwich=False)
    L.fit()

    L = randomized_lasso(y, X, lam, (True, 0.4 * np.diag(np.sqrt(np.diag(np.dot(X.T, X))))),
                         sandwich=True)
    L.fit()
    if (set(range(s)).issubset(L.active) and 
        L.active.shape[0] > s):
        L.constraints.mean[:p] = 0 * L.unbiased_estimate

        v = np.zeros_like(L.active)
        v[s] = 1.
        P0, interval = L.hypothesis_test(v, burnin=burnin, ndraw=ndraw,
                                         compute_interval=compute_interval)
        target = (beta[L.active]*v).sum()
        estimate = (L.unbiased_estimate[:L.active.shape[0]]*v).sum()
        low, hi = interval

        v = np.zeros_like(L.active)
        v[0] = 1.
        PA, _ = L.hypothesis_test(v, burnin=burnin, ndraw=ndraw,
                                  compute_interval=compute_interval)

        return P0, PA, L
def test_gaussian(n=200,
                  p=30,
                  burnin=2000,
                  ndraw=8000,
                  compute_interval=False,
                  sandwich=True,
                  selected=False,
                  s=6,
                  snr=7,
                  nsim=None):

    X, y, beta, lasso_active, sigma = lasso_instance(n=n,
                                                     p=p,
                                                     snr=snr,
                                                     s=s,
                                                     rho=0.1)
    n, p = X.shape

    lam = 2. * sigma * np.mean(
        np.fabs(np.dot(X.T, np.random.standard_normal((n, 10000)))).max(0))

    L = randomized_lasso(
        y,
        X,
        lam, (True, 0.8 * sigma * np.diag(np.sqrt(np.diag(np.dot(X.T, X))))),
        sandwich=sandwich,
        selected=selected,
        dispersion=sigma**2)

    L.fit()
    if (set(range(s)).issubset(L.active) and L.active.shape[0] > s):
        L.unbiased_estimate[:] = np.zeros(p)
        L.constraints.mean[:p] = 0 * L.unbiased_estimate

        v = np.zeros_like(L.active)
        v[s] = 1.
        P0, interval = L.hypothesis_test(v,
                                         burnin=burnin,
                                         ndraw=ndraw,
                                         compute_interval=compute_interval)
        target = (beta[L.active] * v).sum()
        estimate = (L.unbiased_estimate[:L.active.shape[0]] * v).sum()
        low, hi = interval

        v = np.zeros_like(L.active)
        v[0] = 1.
        PA, _ = L.hypothesis_test(v,
                                  burnin=burnin,
                                  ndraw=ndraw,
                                  compute_interval=compute_interval)

        return P0, PA, L
def test_gaussian(n=200, p=30, burnin=2000, ndraw=8000,
                  compute_interval=False,
                  sandwich=True,
                  selected=False,
                  s=6,
                  snr=7,
                  condition_on_more=False,
                  nsim=None):

    X, y, beta, lasso_active, sigma = lasso_instance(n=n, 
                                                     p=p,
                                                     snr=snr,
                                                     s=s,
                                                     rho=0.1)
    n, p = X.shape

    lam = 2. * sigma * np.mean(np.fabs(np.dot(X.T, np.random.standard_normal((n, 10000)))).max(0))

    L = randomized_lasso(y, X, lam, (True, 0.8 * sigma * np.diag(np.sqrt(np.diag(np.dot(X.T, X))))),
                         sandwich=sandwich,
                         selected=selected,
                         dispersion=sigma**2)

    L.fit()
    if (set(range(s)).issubset(L.active) and 
        L.active.shape[0] > s):
        L.unbiased_estimate = np.zeros(p)
        L.constraints.mean[:p] = 0 * L.unbiased_estimate

        v = np.zeros_like(L.active)
        v[s] = 1.
        P0, interval = L.hypothesis_test(v, burnin=burnin, ndraw=ndraw,
                                         compute_interval=compute_interval,
                                         condition_on_more=condition_on_more)
        target = (beta[L.active]*v).sum()
        estimate = (L.unbiased_estimate[:L.active.shape[0]]*v).sum()
        low, hi = interval

        v = np.zeros_like(L.active)
        v[0] = 1.
        PA, _ = L.hypothesis_test(v, burnin=burnin, ndraw=ndraw,
                                  compute_interval=compute_interval,
                                  condition_on_more=condition_on_more)

        return P0, PA, L