コード例 #1
0
def ci_umle(X, v, theta_grid, alpha_level):
    arr = array_from_data(X, [v])
    arr.offset_extremes()
    alpha_zero(arr)

    fit_model = NonstationaryLogistic()

    umle = np.empty_like(theta_grid)
    for l, theta_l in enumerate(theta_grid):
        fit_model.beta['x_0'] = theta_l
        fit_model.fit(arr, fix_beta = True)
        umle[l] = -fit_model.nll(arr)

    crit = -0.5 * chi2.ppf(1 - alpha_level, 1)
    ci = invert_test(theta_grid, umle - umle.max(), crit)
    if params['plot']:
        plot_statistics(ax_umle, theta_grid, umle - umle.max(), crit)
        umle_coverage_data['cis'].append(ci)
        umle_coverage_data['theta_grid'] = theta_grid
        umle_coverage_data['crit'] = crit
    return ci
コード例 #2
0
    net.new_edge_covariate(name).from_binary_function_ind(f_x)

# Specify data model as generation permuation networks
net.new_node_covariate_int('r')[:] = 1
net.new_node_covariate_int('c')[:] = 1
data_model = FixedMargins(data_model, 'r', 'c')

coverage_levels = np.append(0.0, np.cumsum(params['coverage_increments']))
traces = { 'wall_time': [],
           'nll': [] }

for rep in range(params['num_reps']):
    net.generate(data_model, arbitrary_init = params['arb_init'])

    wall_time_trace = [net.gen_info['wall_time']]
    nll_trace = [data_model.nll(net)]

    for coverage_inc in params['coverage_increments']:
        data_model.gibbs_improve_perm(net, net.adjacency_matrix(), coverage_inc)

        wall_time_trace.append(net.gen_info['wall_time'])
        nll_trace.append(data_model.nll(net))

    traces['wall_time'].append(wall_time_trace)
    traces['nll'].append(nll_trace)

plt.figure()
plt.title('Computation time')
plt.xlabel('Coverage level')
plt.ylabel('Wall time (msec)')
for rep in range(params['num_reps']):
コード例 #3
0
for cov_name in cov_names:
    s_model.beta[cov_name] = None
s_model.fit(net, verbose=True)
print 'NLL: %.2f' % s_model.nll(net)
print 'kappa: %.2f' % s_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, s_model.beta[cov_name])
print

print 'Fitting nonstationary model'
alpha_zero(net)
ns_model = NonstationaryLogistic()
for cov_name in cov_names:
    ns_model.beta[cov_name] = None
ns_model.fit(net, verbose=True)
print 'NLL: %.2f' % ns_model.nll(net)
print 'kappa: %.2f' % ns_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, ns_model.beta[cov_name])
print

print 'Fitting conditional model'
c_model = StationaryLogistic()
for cov_name in cov_names:
    c_model.beta[cov_name] = None
c_model.fit_conditional(net, T=0, verbose=True)
print 'NLL: %.2f' % c_model.nll(net)
print 'kappa: %.2f' % c_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, c_model.beta[cov_name])
print
コード例 #4
0
c_model.confidence_boot(net, n_bootstrap = params['n_bootstrap'])
c_model.confidence_wald(net)
for cov_name in cov_names:
    c_model.confidence_cons(net, cov_name, L = 121, test = 'score')
    c_model.confidence_cons(net, cov_name, L = 121, test = 'lr')
display_cis(c_model)

# Offset extreme substructure only for Nonstationary model
net.offset_extremes()

print 'Fitting nonstationary model'
ns_model = NonstationaryLogistic()
for cov_name in cov_names:
    ns_model.beta[cov_name] = None
ns_model.fit(net)
print 'NLL: %.2f' % ns_model.nll(net)
print 'kappa: %.2f' % ns_model.kappa
for cov_name in cov_names:
    print '%s: %.2f' % (cov_name, ns_model.beta[cov_name])
print
for rep in range(params['n_samples']):
    ns_samples[rep,:,:] = ns_model.generate(net)
ns_model.confidence_boot(net, n_bootstrap = params['n_bootstrap'])
ns_model.confidence_wald(net)
display_cis(ns_model)

# Calculate sample means and variances
s_samples_mean = np.mean(s_samples, axis = 0)
s_samples_sd = np.sqrt(np.var(s_samples, axis = 0))
ns_samples_mean = np.mean(ns_samples, axis = 0)
ns_samples_sd = np.sqrt(np.var(ns_samples, axis = 0))
コード例 #5
0
for cov_name in cov_names:
    s_model.beta[cov_name] = None
s_model.fit(net, verbose=True)
print "NLL: %.2f" % s_model.nll(net)
print "kappa: %.2f" % s_model.kappa
for cov_name in cov_names:
    print "%s: %.2f" % (cov_name, s_model.beta[cov_name])
print

print "Fitting nonstationary model"
alpha_zero(net)
ns_model = NonstationaryLogistic()
for cov_name in cov_names:
    ns_model.beta[cov_name] = None
ns_model.fit(net, verbose=True)
print "NLL: %.2f" % ns_model.nll(net)
print "kappa: %.2f" % ns_model.kappa
for cov_name in cov_names:
    print "%s: %.2f" % (cov_name, ns_model.beta[cov_name])
print

print "Fitting conditional model"
c_model = FixedMargins(StationaryLogistic())
for cov_name in cov_names:
    c_model.base_model.beta[cov_name] = None
c_model.base_model.fit_conditional(net, verbose=True)
print "NLL: %.2f" % c_model.nll(net)
for cov_name in cov_names:
    print "%s: %.2f" % (cov_name, c_model.base_model.beta[cov_name])
print