def plotWassersteinConvergenceReferenceSolution(name, basename, resolutions, number_of_integration_points): comm = MPI.COMM_WORLD rank = comm.Get_rank() wasserstein2pterrors = [] reference_resolution = resolutions[-1] for r in resolutions[:-1]: if rank == 0: print(r) filename = basename.format(resolution=reference_resolution) filename_coarse = basename.format(resolution=r) wasserstein2pterrors.append( wasserstein2pt_fast(filename, filename_coarse, reference_resolution, number_of_integration_points)) if rank == 0: print("wasserstein2pterrors={}".format(wasserstein2pterrors)) # Only plot from rank 0 if rank == 0: plt.loglog(resolutions[:-1], wasserstein2pterrors, '-o', basex=2, basey=2) plt.xlabel("Resolution") min_value_log = np.floor(np.log2(np.min(wasserstein2pterrors))) max_value_log = np.ceil(np.log2(np.max(wasserstein2pterrors))) plt.ylim([2**min_value_log, 2**max_value_log]) plt.xticks(resolutions[:-1], ['${r}^3$'.format(r=r) for r in resolutions[1:]]) plt.ylabel( f'$||W_1(\\nu^{{2, N}}, \\nu^{{2,{reference_resolution}}})||_{{L^1(D\\times D)}}$' ) plt.title("""Wasserstein convergence for {title} for second correlation marginal (against reference solution) Using ${number_of_integration_points}^6={total_integration_points}$ equidistant integration points """.format(title=name, number_of_integration_points=number_of_integration_points, total_integration_points=number_of_integration_points**6)) showAndSave('%s_wasserstein_convergence_reference_2pt' % name) saveData('%s_wasserstein_convergence_reference_2pt_resolutions' % name, resolutions) saveData('%s_wasserstein_convergence_reference_2pt_wasserstein' % name, wasserstein2pterrors)
min_per_iteration[iteration] = np.min(samples) max_per_iteration[iteration] = np.max(samples) iterations_mesh, edges_mesh = np.meshgrid(np.arange(0, max_number_of_iterations), np.linspace(min_value, max_value, bins)) plt.pcolormesh(iterations_mesh, edges_mesh, histograms.T) plt.colorbar() plt.xscale('log', basex=2) plt.yscale('log', basey=2) plt.xlabel("Number of evaluations of the simulator") plt.ylabel("Minimum value") plt.axvline(512, color='grey', linestyle='--') plt.axvline(256, color='green', linestyle='--') plt.axhline(0.55, color='green', linestyle='--') plt.axhline(0.45, color='grey', linestyle='--') plot_info.showAndSave("optimized_traditional_histograms") number_of_iterations = np.arange(0, max_number_of_iterations) #plt.fill_between(number_of_iterations, mean_per_iteration-std_per_iteration, mean_per_iteration+std_per_iteration, # alpha=0.5, color='C1', label=r'mean $\pm$ std') plt.fill_between(number_of_iterations, min_per_iteration, max_per_iteration, alpha=0.5, color='C1', label=r'min-max') plt.plot(number_of_iterations, mean_per_iteration, label='mean') #plt.ylim([min_value, 4*max_value]) plt.axvline(512, color='grey', linestyle='--') plt.axvline(256, color='green', linestyle='--') plt.axhline(0.55, color='green', linestyle='--') plt.axhline(0.45, color='grey', linestyle='--') plt.xscale('log', basex=2) plt.yscale('log', basey=2) plt.xlabel("Number of evaluations of the simulator")
import matplotlib.pyplot as plt import json import numpy import sys import objective import heat import plot_info with open('objective_parameters.json') as f: objective_parameters = json.load(f) objective_function = objective.Objective(**objective_parameters) initial_data = objective_function.initial_data dt = 1.0 / 2048 dx = 1.0 / 2048 end_time = objective_parameters['end_time'] solution = heat.solve_heat_equation(initial_data, dt, dx, end_time) x = numpy.arange(0, 1, dx) plt.plot(x, initial_data(x), label='initial') plt.plot(x, solution, '*', label='numerical') plt.plot(x, initial_data.exact_solution(x, end_time), label='exact') plt.legend() plot_info.showAndSave("heat_exact_solution")
data_M_samples_upscaled = np.repeat(data[:M], reference_size / M, 0) errors.append( scipy.stats.wasserstein_distance(data[:reference_size], data_M_samples_upscaled)) plt.loglog(Ms, errors, '-o', label='$W_1(\\mu^{M}, \\mu^{\\mathrm{Ref}})$') plt.xlabel('Number of samples $M$') plt.ylabel("Wasserstein distance $W_1$") plt.title( "Wasserstein convergence of {func_name} for {data_source_name}". format(func_name=func_name, data_source_name=data_source_name)) poly = np.polyfit(np.log(Ms), np.log(errors), 1) plt.loglog(Ms, np.exp(poly[1]) * Ms**poly[0], '--', label='$\\mathcal{O}(M^{%.2f})$' % poly[0]) plt.legend() plot_info.showAndSave( "wasserstein_convergence_{data_source_name}_{func_name}".format( func_name=func_name, data_source_name=data_source_name)) # In[ ]:
axes[plot_index].set_xlabel("Iteration") plot_ref = axes[number_of_plots].plot(iterations, coefficients_per_iteration[:, 0], '-o', label='q') axes[number_of_plots].plot(iterations, np.zeros_like(coefficients_per_iteration[:, 0]) * objective_parameters['q'], '--', label='q', color=plot_ref[0].get_color()) axes[number_of_plots].grid(True) axes[number_of_plots].legend() axes[number_of_plots].set_xlabel("Iteration") plot_info.showAndSave("coefficients") dx = 1.0 / 2048 x = np.arange(0, 1, dx) objective_function = objective.Objective(**objective_parameters) initial_data = objective_function.initial_data end_time = objective_parameters['end_time'] #plt.plot(x, initial_data.exact_solution(x, end_time), label='exact true') objective_function_approximated = objective.Objective( end_time=end_time, coefficients=coefficients_per_iteration[-1, 1:], q=coefficients_per_iteration[-1, 0], control_points=objective_parameters['control_points'])