示例#1
0
def test_get_populations_from_alpha_1D_exponential():
    scale = 3.0
    prior_pops, predictions = generate_exponential_data(5000000, 1, scale)
    alpha = np.array([0.25])
    populations = belt.get_populations_from_alpha(alpha, predictions, prior_pops)
    mu = predictions.T.dot(populations)
    mu0 = (alpha + scale ** -1.)**-1.
    eq(mu0, mu, decimal=3)
示例#2
0
def test_get_populations_from_alpha_1D_uniform():
    prior_pops, predictions = generate_uniform_data(5000000, 1)
    alpha = np.array([0.25])
    populations = belt.get_populations_from_alpha(alpha, predictions, prior_pops)
    mu = predictions.T.dot(populations)
    a = alpha
    mu0 = (1. / a) - 1. / (np.exp(a) - 1.)
    eq(mu0, mu, decimal=3)
hist(d3, bins=100, color='k', normed=True)
hist(d4, bins=100, color='k', normed=True)
setp(ax2.get_xticklabels(), visible=False)
setp(ax2.get_yticklabels(), visible=False)
xlim(-180, 180)
ylabel("Deg.")



ax2 = subplot(413)
p0 = np.ones(n) / n
hist(phi1, bins=100, color='k', normed=True, weights=prior_pops)
#yticks([0, 0.05, 0.1])
setp(ax2.get_xticklabels(), visible=False)
setp(ax2.get_yticklabels(), visible=False)
xlim(-180, 180)
ylabel("MD")


locations = range(1000, 4500, 400)
ax2 = subplot(414)
for k, location in enumerate(locations):
    pops = belt.get_populations_from_alpha(ai[location], predictions.values, prior_pops)
    hist(phi1, bins=100, weights=pops, histtype='step', color='k', alpha=0.5) 
    setp(ax2.get_yticklabels(), visible=False)
    xlim(-180, 180)

ylabel("BELT")
xlabel(r"$\phi$")
plt.savefig(ALA3.outdir + "/karplus_four_panels.pdf", bbox_inches='tight')
belt.ne.set_num_threads(3)

regularization_strength = 1E-6
prior = "maxent"
pops = {}

for ff in ALA3.ff_list:
    print(ff)

    phi, psi, ass_raw, state_ind = experiment_loader.load_rama(ff, ALA3.stride)
    predictions, measurements, uncertainties = experiment_loader.load(ff)

    num_frames, num_measurements = predictions.shape
    bootstrap_index_list = np.array_split(np.arange(num_frames), ALA3.num_blocks)

    prior_pops = None

    model = belt.MaxEntBELT(predictions.values, measurements.values, uncertainties.values, regularization_strength, prior_pops=prior_pops)

    model.sample(10)

    MAP = pymc.MAP(model)
    MAP.fit()

    alpha = MAP.alpha.value

    p = belt.get_populations_from_alpha(alpha, predictions.values, model.prior_pops)
    pops[ff] = p[ass_raw == 0].sum(), p[ass_raw == 1].sum(), p[ass_raw == 2].sum()

pops = pd.DataFrame(pops)
z = np.random.normal(size=(num_frames, 1))
rho = np.random.random_integers(0, 1, size=(num_frames, 1)) * 2 - 1
x = 0.5 * (z + 2) * rho
prior_pops = np.ones(num_frames) / float(num_frames)

num_bins = 50
use_log = False
scale = 1.0
ymin = 1E-5
ymax = 0.12

num_grid = 100
grid = np.linspace(-7, 7, num_grid)

alpha = np.array([0.0])
p = belt.get_populations_from_alpha(alpha, x, prior_pops)
plt.hist(x, weights=p, bins=num_bins,color="b", log=use_log)
y = grid * alpha[0]
#plt.plot(grid, y, 'k')
plt.title(r"$\alpha_1 = 0$")
plt.xlabel("Observable: $f_1(x)$")
plt.ylabel("Population")
plt.ylim([ymin, ymax])
plt.savefig(ALA3.outdir+"/model_hist0.pdf",bbox_inches='tight')

alpha = np.array([-scale])
p = belt.get_populations_from_alpha(alpha, x, prior_pops)
plt.figure()
plt.hist(x,weights=p,bins=num_bins,color="g", log=use_log)
y = grid * alpha[0]
#plt.plot(grid, y, 'k')
示例#6
0
def test_get_populations_from_alpha_2D_gaussian():
    prior_pops, predictions = generate_gaussian_data(5000000, 2)
    alpha = np.array([-0.25, 0.25])
    populations = belt.get_populations_from_alpha(alpha, predictions, prior_pops)
    mu = predictions.T.dot(populations)
    eq(mu, -1.0 * alpha, decimal=2)