コード例 #1
0
def forward_sample(X,
                   n_iters,
                   Zv=None,
                   Zrcv=None,
                   n_grid=30,
                   n_chains=1,
                   ct_kernel=0):
    total_iters = n_chains * n_iters
    n_cols = len(X)
    cctypes = ['normal'] * n_cols
    distargs = [None] * n_cols
    forward_samples = dict()
    stats = []
    i = 0
    for chain in range(n_chains):
        forward_samples[chain] = []
        for itr in range(n_iters):
            i += 1
            state = cc_state.cc_state(X,
                                      cctypes,
                                      distargs,
                                      Zv=Zv,
                                      Zrcv=Zrcv,
                                      n_grid=n_grid,
                                      ct_kernel=ct_kernel)
            Y = su.resample_data(state)
            forward_samples[chain].append(Y)
            stats.append(get_data_stats(Y, state))
            string = "\r%1.2f  " % (i * 100.0 / float(total_iters))
            sys.stdout.write(string)
            sys.stdout.flush()

    return stats, forward_samples
コード例 #2
0
ファイル: geweke_test.py プロジェクト: BaxterEaves/BaxCat
def posterior_sample(X, n_iters, kernels=_all_kernels, Zv=None, Zrcv=None, n_grid=30, n_chains=1, ct_kernel=0):
    n_cols = len(X)
    cctypes = ['normal']*n_cols
    distargs = [None]*n_cols
    stats = []
    posterior_samples = dict()
    i = 0.0;
    total_iters = n_chains*n_iters
    for chain in range(n_chains):
        state = cc_state.cc_state(X, cctypes, distargs, Zv=Zv, Zrcv=Zrcv, n_grid=n_grid, ct_kernel=ct_kernel)
        Y = su.resample_data(state)
        posterior_samples[chain] = Y
        for _ in range(n_iters):
            state.transition(kernel_list=kernels)
            Y = su.resample_data(state)
            stats.append(get_data_stats(Y, state))
            posterior_samples[chain].append(Y)
            i += 1.0
            string = "\r%1.2f  " % (i*100.0/float(total_iters))
            sys.stdout.write(string)
            sys.stdout.flush()
            
    return stats, posterior_samples
コード例 #3
0
def posterior_sample(X,
                     n_iters,
                     kernels=_all_kernels,
                     Zv=None,
                     Zrcv=None,
                     n_grid=30,
                     n_chains=1,
                     ct_kernel=0):
    n_cols = len(X)
    cctypes = ['normal'] * n_cols
    distargs = [None] * n_cols
    stats = []
    posterior_samples = dict()
    i = 0.0
    total_iters = n_chains * n_iters
    for chain in range(n_chains):
        state = cc_state.cc_state(X,
                                  cctypes,
                                  distargs,
                                  Zv=Zv,
                                  Zrcv=Zrcv,
                                  n_grid=n_grid,
                                  ct_kernel=ct_kernel)
        Y = su.resample_data(state)
        posterior_samples[chain] = Y
        for _ in range(n_iters):
            state.transition(kernel_list=kernels)
            Y = su.resample_data(state)
            stats.append(get_data_stats(Y, state))
            posterior_samples[chain].append(Y)
            i += 1.0
            string = "\r%1.2f  " % (i * 100.0 / float(total_iters))
            sys.stdout.write(string)
            sys.stdout.flush()

    return stats, posterior_samples
コード例 #4
0
ファイル: geweke_test.py プロジェクト: BaxterEaves/BaxCat
def forward_sample(X, n_iters, Zv=None, Zrcv=None, n_grid=30, n_chains=1, ct_kernel=0):
    total_iters = n_chains*n_iters
    n_cols = len(X)
    cctypes = ['normal']*n_cols
    distargs = [None]*n_cols
    forward_samples = dict()
    stats = []
    i = 0
    for chain in range(n_chains):
        forward_samples[chain] = []
        for itr in range(n_iters):
            i += 1
            state = cc_state.cc_state(X, cctypes, distargs, Zv=Zv, Zrcv=Zrcv, n_grid=n_grid, ct_kernel=ct_kernel)
            Y = su.resample_data(state)
            forward_samples[chain].append(Y)
            stats.append(get_data_stats(Y, state))
            string = "\r%1.2f  " % (i*100.0/float(total_iters))
            sys.stdout.write(string)
            sys.stdout.flush()

    return stats, forward_samples