Esempio n. 1
0
def geweke_joint_distribution_test(trace_1, trace_2, g):
    '''
    Compare whether the trace of two samples have converged to the same stationary distribution.
    
    Returns :
        p : p-value two simulators are drawing from same joint distribution.
    
    ''' 
    g_1 = [g(x) for x in trace_1]
    g_2 = [g(x) for x in trace_2]
    
    z = two_sample_z_score(g_1, g_2)
    
    return 1 - inverse_normal_cdf(z)
Esempio n. 2
0
def geweke_convergence_test(trace, first=0.1, last=0.5):
    # Filter out invalid intervals
    if first + last >= 1:
        raise ValueError("Length of intervals must sum to <= 1. Values {0} and {1} sum to {2}.".format(first,
                                                                                                       last,
                                                                                                       first + last))

    # Calculate starting indices
    end_of_first_slice = int(len(trace) * first)
    
    start_of_last_slice = int(len(trace) * (1 - last))

    # Calculate slices
    first_slice = trace[:end_of_first_slice]
    last_slice = trace[start_of_last_slice:]
    
    z = two_sample_z_score(first_slice, last_slice)
    
    return 1 - inverse_normal_cdf(z)
Esempio n. 3
0
    alpha, partition = draw_from_prior(base_measure, size)

    observed_p = partition.item_values[0].x

    params = [param.x for param in partition.item_values]

    data = draw_data(params, n)

    sampler = Sampler(base_measure, cluster_density)

    posterior = []

    for _ in range(num_iters):
        alpha, partition = sampler.sample(alpha, partition, data)

        posterior.append(partition.item_values[0].x)

    q = 0

    for value in posterior:
        if observed_p > value:
            q += 1

    q = q / len(posterior)

    print q, inverse_normal_cdf(q), observed_p, mean(posterior)

    test_stat.append(inverse_normal_cdf(q)**2)

print 1 - chi_square_cdf(sum(test_stat), len(test_stat))