import h5py from MakeFigure import * # Read data from file filename = 'iceberg_mcmc.h5' hdf5file = h5py.File(filename, 'r') t1 = hdf5file['data_mcmc/theta1'].value t2 = hdf5file['data_mcmc/theta2'].value acc_rate = hdf5file['data_mcmc/acc_rate'].value print("Acceptance rate = ", acc_rate) # Mixing graphs for theta1 and theta2 fig = MakeFigure(450, 1) ax = plt.gca() ax.set_title('Water Coefficient Mixing', fontsize=12) ax.set_xlabel('Iterations', fontsize=10) ax.set_ylabel('Water Coefficient ($Cw$)', fontsize=10) ax.plot(t1) fig = MakeFigure(450, 1) ax = plt.gca() ax.set_title('Air Coefficient Mixing', fontsize=12) ax.set_xlabel('Iterations', fontsize=10) ax.set_ylabel('Air Coefficient ($Ca$)', fontsize=10) ax.plot(t2) # Scatter Plot fig = MakeFigure(450, 1) ax = plt.gca()
theta1 = np.linspace(1.3, 2, t1_size) theta2 = np.linspace(1.3, 2, t2_size) startTime = datetime.now() print(startTime) log_prior = np.empty(shape=(t2_size, t1_size)) log_likelihood = np.empty(shape=(t2_size, t1_size)) log_posterior = np.empty(shape=(t2_size, t1_size)) for i in range(t2_size): for j in range(t1_size): log_prior[i][j] = post.log_prior([theta1[j], theta2[i]]) log_likelihood[i][j] = post.log_likelihood([theta1[j], theta2[i]]) log_posterior[i][j] = log_prior[i][j] + log_likelihood[i][j] print(i, datetime.now() - startTime) fig = MakeFigure(700, 0.75) ax = plt.gca() ax.contourf(theta1, theta2, np.exp(np.array(log_prior))) ax.set_title('Prior', fontsize=16) ax.set_xlabel('Water Coefficient ($Cw$)', fontsize=12) ax.set_ylabel('Air Coefficient ($Ca$)', fontsize=12) fig = MakeFigure(700, 1) ax = plt.gca() cont = ax.contourf(theta1, theta2, np.exp(np.array(log_likelihood))) plt.colorbar(cont) ax.set_title('Likelihood', fontsize=16) ax.set_xlabel('Water Coefficient ($Cw$)', fontsize=12) ax.set_ylabel('Air Coefficient ($Ca$)', fontsize=12) fig = MakeFigure(700, 1)
projection_cluster_assignment1 = get_cluster_assignment(s1_density_clean, projection1, "s1_decision_graph.png", interactive, dir_name) projection_cluster_assignment2 = get_cluster_assignment(s2_density_clean, projection2, "s2_decision_graph.png", interactive, dir_name) clusters1, outliers1 = get_top_clusters(5, dihedral_angle1, projection_cluster_assignment1) clusters2, outliers2 = get_top_clusters(5, dihedral_angle2, projection_cluster_assignment2) projection1_clean = projection1[np.argwhere(projection_cluster_assignment1 != 0).flatten()] projection2_clean = projection2[np.argwhere(projection_cluster_assignment2 != 0).flatten()] print("Calculating NIP scores...") h1_clean, h2_clean = create_histogram(projection1_clean, projection2_clean) NIP_clean = calc_NIP(h1_clean, h2_clean) NIP_ttl = calc_NIP(h1, h2) print("Plotting...") MakeFigure(clusters1, res_name, u1_num_frame, NIP_ttl[0], NIP_clean[0], "s1_rama.png", dir_name) MakeFigure(clusters2, res_name, u2_num_frame, NIP_ttl[1], NIP_clean[1], "s2_rama.png", dir_name) plt.close('all') if time_procedure: end = time.perf_counter() print("=" * 80) print(f"This analysis procedure finishes in {end - start:0.4f} seconds") if debug: covar = pca.get_covariance() np.savetxt("covar.dat", covar, fmt="%10.6f") np.savetxt("dihedral.trr", trig_trr_ttl, fmt="%10.6f") np.savetxt("projection.txt", projection, fmt="%10.6f") np.savetxt("s1_projection.txt", projection1, fmt="%10.6f") np.savetxt("s2_projection.txt", projection2, fmt="%10.6f")
ObsData = ForwardModel(tobs, theta, state0) xobs = [x[0] for x in ObsData] yobs = [y[1] for y in ObsData] cov = np.diag([sig2] * T) x_noise = np.random.multivariate_normal([0.0] * T, cov) y_noise = np.random.multivariate_normal([0.0] * T, cov) x_data = xobs + x_noise y_data = yobs + y_noise WriteData(hdf5file, 'data/xobs', x_data) WriteData(hdf5file, 'data/yobs', y_data) time = np.linspace(t0, tf, 1000) TrueData = ForwardModel(time, theta, state0) xtrue = [x[0] for x in TrueData] ytrue = [y[1] for y in TrueData] fig = MakeFigure(425, 0.9) ax = plt.gca() ax.plot(xtrue, ytrue, color='#111111') ax.plot(x_data, y_data, 'o', markerfacecolor='#000cff', markeredgecolor='#000cff', markersize=8) ax.set_xlabel('Longitude', fontsize=30, color='#969696') ax.set_ylabel('Latitude', fontsize=30, color='#969696') plt.show()