def test_regression_2(self):
     np.random.seed(42)
     data = np.random.randn(100) * 2.0
     me = GaussianQuadraticTest(self.grad_log_normal)
     U_stat,_ = me.get_statistic_multiple(data)
     pval = me.compute_pvalue(U_stat)
     assert pval == 0.0
 def test_regression_2(self):
     np.random.seed(42)
     data = np.random.randn(100) * 2.0
     me = GaussianQuadraticTest(self.grad_log_normal)
     U_stat, _ = me.get_statistic_multiple(data)
     pval = me.compute_pvalue(U_stat)
     assert pval == 0.0
 def test_get_statistic_multiple_equals_get_statistic(self):
     N = 10
     X = np.random.randn(N)
     me = GaussianQuadraticTest(self.grad_log_normal)
     U_matrix_multiple, stat_multiple = me.get_statistic_multiple(X)
     U_matrix, stat = me.get_statisitc(N, X)
     
     assert_allclose(stat, stat_multiple)
     assert_allclose(U_matrix_multiple, U_matrix)
    def test_get_statistic_multiple_equals_get_statistic(self):
        N = 10
        X = np.random.randn(N)
        me = GaussianQuadraticTest(self.grad_log_normal)
        U_matrix_multiple, stat_multiple = me.get_statistic_multiple(X)
        U_matrix, stat = me.get_statisitc(N, X)

        assert_allclose(stat, stat_multiple)
        assert_allclose(U_matrix_multiple, U_matrix)
Beispiel #5
0
dfs = range(1, 4, 2)
mc_reps = 100
res = np.empty((0, 2))

block = N / np.log(N)
p_change = 1.0 / block
print(p_change)

for df in dfs:

    for mc in range(mc_reps):
        print(mc)
        X = almost_t_student(10 * N, df, 0.01)
        X = X[::10]
        me = GaussianQuadraticTest(grad_log_normal)
        U_stat, _ = me.get_statistic_multiple(X)

        pval = me.compute_pvalues_for_processes(U_stat, p_change)
        res = np.vstack((res, np.array([df, pval])))

for mc in range(mc_reps):
    X = almost_t_student(10 * N, 100, 0.01)
    X = X[::10]
    me = GaussianQuadraticTest(grad_log_normal)
    U_stat, _ = me.get_statistic_multiple(X)
    pval = me.compute_pvalues_for_processes(U_stat, p_change)
    res = np.vstack((res, np.array([np.Inf, pval])))

np.save('results.npy', res)

df = DataFrame(res)
    grad = lambda x: est.grad(np.array([x]))[0]
    s =  GaussianQuadraticTest(grad)
    num_bootstrap = 200
    
    result_fname = os.path.splitext(os.path.basename(__file__))[0] + ".txt"
    
    num_repetitions = 150
    for _ in range(num_repetitions):
        for m in ms_fit:
            est = KernelExpFiniteGaussian(sigma, lmbda, m, D)
            X_test = np.random.randn(N_test, D)
            
            X = np.random.randn(N_fit, D)
            est.fit(X)
            
            U_matrix, stat = s.get_statistic_multiple(X_test[:,0])
        
            bootsraped_stats = np.empty(num_bootstrap)
            for i in range(num_bootstrap):
                W = np.sign(np.random.randn(N_test))
                WW = np.outer(W, W)
                st = np.mean(U_matrix * WW)
                bootsraped_stats[i] = N_test * st
            
            p_value = np.mean(bootsraped_stats>stat)
            print m, p_value

            store_results(result_fname,
                          D=D,
                          N_fit=N_fit,
                          N_test=N_test,
    grad = lambda x: est.grad(np.array([x]))[0]
    s = GaussianQuadraticTest(grad)
    num_bootstrap = 200

    result_fname = os.path.splitext(os.path.basename(__file__))[0] + ".txt"

    num_repetitions = 150
    for _ in range(num_repetitions):
        for m in ms_fit:
            est = KernelExpFiniteGaussian(sigma, lmbda, m, D)
            X_test = np.random.randn(N_test, D)

            X = np.random.randn(N_fit, D)
            est.fit(X)

            U_matrix, stat = s.get_statistic_multiple(X_test[:, 0])

            bootsraped_stats = np.empty(num_bootstrap)
            for i in range(num_bootstrap):
                W = np.sign(np.random.randn(N_test))
                WW = np.outer(W, W)
                st = np.mean(U_matrix * WW)
                bootsraped_stats[i] = N_test * st

            p_value = np.mean(bootsraped_stats > stat)
            print m, p_value

            store_results(result_fname,
                          D=D,
                          N_fit=N_fit,
                          N_test=N_test,
dfs = range(1, 4, 2)
mc_reps = 100
res = np.empty((0,2))

block = N/np.log(N)
p_change  = 1.0/block
print(p_change)

for df in dfs:

    for mc in range(mc_reps):
        print(mc)
        X = almost_t_student(10*N,df,0.01)
        X = X[::10]
        me = GaussianQuadraticTest(grad_log_normal)
        U_stat,_ = me.get_statistic_multiple(X)

        pval = me.compute_pvalues_for_processes(U_stat,p_change)
        res = np.vstack((res,np.array([df, pval])))

for mc in range(mc_reps):
        X = almost_t_student(10*N,100,0.01)
        X = X[::10]
        me = GaussianQuadraticTest(grad_log_normal)
        U_stat,_ = me.get_statistic_multiple(X)
        pval = me.compute_pvalues_for_processes(U_stat,p_change)
        res = np.vstack((res,np.array([np.Inf, pval])))

np.save('results.npy',res)

df = DataFrame(res)