def plot_from_data(T_data, C_data, fname=None, ax=None, axins=None, Tmax=0.25): if fname is not None: base = fname[:-4] method = os.path.split(fname)[-1].split('+')[0] if method == 'itwl': label = r'$1/t$-WL' + r'-$E_{barr}$=0.' + styles.get_barrier( base)[0] if method == 'sad': label = r'SAD' + r'-$E_{barr}$=0.' + styles.get_barrier(base)[0] if method == 'z': label = r'ZMC' + r'-$E_{barr}$=0.' + styles.get_barrier(base)[0] if method == 'tem': label = r'TEM' + r'-$E_{barr}$=0.' + styles.get_barrier(base)[0] else: base = None method = None label = 'exact' _, t_peak, _ = _set_temperatures(ax=ax, axins=axins, Tmax=Tmax) ax.plot(T_data, C_data, label=label, marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) # inset axes.... #axins = ax.inset_axes( 0.5 * np.array([1, 1, 0.47/0.5, 0.47/0.5]))#[0.005, 0.012, 25, 140]) axins.plot(T_data, C_data, label=label, marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) x1, x2, y1, y2 = 0.002, 0.009, 5, 30 # axins.set_xlim(x1, x2) axins.set_ylim(y1, y2)
def plot(S, fname=None, ax=None, axins=None, Tmax=0.25): timer = Timer(f'heat_capacity.plot {fname}') if fname is not None: base = fname[:-8] method = base[:base.find('-')] else: base = None method = None t_low, t_peak, t_high = _set_temperatures(ax=ax, axins=axins, Tmax=Tmax) timer_low_T = Timer('C for low T') c_low = np.array([C(T, S) for T in t_low]) del timer_low_T timer_peak = Timer('C for peak T') c_peak = np.array([C(T, S) for T in t_peak]) del timer_peak c_high = np.array([C(T, S) for T in t_high]) ax.plot(np.concatenate((t_low, t_peak, t_high)), np.concatenate((c_low, c_peak, c_high)), label=styles.pretty_label(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) # inset axes.... #axins = ax.inset_axes( 0.5 * np.array([1, 1, 0.47/0.5, 0.47/0.5]))#[0.005, 0.012, 25, 140]) axins.plot(np.concatenate((t_low, t_peak, t_high)), np.concatenate((c_low, c_peak, c_high)), label=styles.pretty_label(base), marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10)
% (seed, ww, ff, N, method) wildfilename = "data/s%03d/periodic-ww%04.2f-ff%04.2f-N%d-%s-%%s.dat" \ % (seed, ww, ff, N, method) with open(filename, 'r') as content_file: content = content_file.read() init_iters[method].append(int(initialization_iters_regex.findall(content)[0])) E_data = numpy.loadtxt(wildfilename % 'E', ndmin=2) Emins[method].append(E_data[:, 0].max()) sample_data = numpy.loadtxt(wildfilename % 'ps', ndmin=2) samples[method].append(sample_data[len(sample_data[:,1])-1, 1]) plt.figure('iters') plt.semilogy(all_Ns, init_iters[method], styles.color(method)+'.-', label=styles.title(method)) plt.figure('emin') plt.plot(all_Ns, Emins[method],styles.color(method)+'.-', label=styles.title(method)) plt.figure('iters') plt.xlabel('$N$') plt.ylabel('Initialization iterations') plt.legend(loc='best').get_frame().set_alpha(0.25) plt.tight_layout(pad=0.2) plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-scaling.pdf" % (ww*100, ff*100)) plt.figure('emin') plt.xlabel('$N$') plt.ylabel('Emin') plt.legend(loc='best').get_frame().set_alpha(0.25)
def plot(S, fname=None, ax=None, axins=None, Tmax=0.25): timer = Timer(f'heat_capacity.plot {fname}') if fname is not None: base = fname[:-8] method = base[:base.find('-')] else: base = None method = None # print('peak should be at', T_peak) T_width = T_peak * 0.7 # this is just a guess t_low = np.linspace(T_peak / 2, T_peak - T_width, 50) t_peak = np.linspace(T_peak - T_width, T_peak + T_width, 150) axins.set_xlim(T_peak - T_width, T_peak + T_width) t_high = np.linspace(T_peak + T_width, Tmax, 50) try: c_low = np.loadtxt(f'{base}-cv_low_saved.txt') except: timer_low_T = Timer('C for low T') c_low = np.array([C(T, S) for T in t_low]) del timer_low_T np.savetxt(f'{base}-cv_low_saved.txt', c_low) try: c_peak = np.loadtxt(f'{base}-cv_peak_saved.txt') except: c_peak = np.array([C(T, S) for T in t_peak]) np.savetxt(f'{base}-cv_peak_saved.txt', c_peak) try: c_high = np.loadtxt(f'{base}-cv_high_saved.txt') except: c_high = np.array([C(T, S) for T in t_high]) np.savetxt(f'{base}-cv_high_saved.txt', c_high) if method in {'wl', 'itwl', 'sad'}: ax.plot(np.concatenate((t_low, t_peak, t_high)), np.concatenate((c_low, c_peak, c_high)), label=styles.pretty_label(base), marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) elif method == 'z': ax.plot(np.concatenate((t_low, t_peak, t_high)), np.concatenate((c_low, c_peak, c_high)), label=styles.pretty_label(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) else: ax.plot(np.concatenate((t_low, t_peak, t_high)), np.concatenate((c_low, c_peak, c_high)), ':', label='exact', linewidth=2, color='tab:cyan') # inset axes.... #axins = ax.inset_axes( 0.5 * np.array([1, 1, 0.47/0.5, 0.47/0.5]))#[0.005, 0.012, 25, 140]) if method in {'wl', 'itwl', 'sad'}: precision = base[base.rfind('-') + 1:] axins.plot(t_peak, c_peak, label=styles.pretty_label(base), marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) elif method == 'z': axins.plot(t_peak, c_peak, label=styles.pretty_label(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=10) else: axins.plot(t_peak, c_peak, ':', label='exact', linewidth=2, color='tab:cyan')
reference_error = mean_u_err(ww, ff, N, reference, golden_u) if reference_error == None: continue print ' ', reference, reference_error for method in methods: plt.figure(2) method_err = mean_u_err(ww, ff, N, method, golden_u) if method_err != None: print ' ', method, method_err plt.figure(1) if method not in labels_added: plt.loglog(reference_error, method_err, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method), label=styles.title(method)) labels_added |= set([method]) else: plt.loglog(reference_error, method_err, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method)) plt.figure(2) plt.figure(2) plt.legend(loc='best') plt.savefig('figs/energy-for-debugging-ww%04.2f-ff%04.2f-N%i.pdf' % (ww, ff, N)) min_T = 0.2 # FIXME maybe shouldn't hardcode this?
with open(filename, 'r') as content_file: content = content_file.read() init_iters[method].append( int(initialization_iters_regex.findall(content)[0])) E_data = numpy.loadtxt(wildfilename % 'E', ndmin=2) Emins[method].append(E_data[:, 0].max()) sample_data = numpy.loadtxt(wildfilename % 'ps', ndmin=2) samples[method].append(sample_data[len(sample_data[:, 1]) - 1, 1]) plt.figure('iters') plt.semilogy(all_Ns, init_iters[method], styles.color(method) + '.-', label=styles.title(method)) plt.figure('emin') plt.plot(all_Ns, Emins[method], styles.color(method) + '.-', label=styles.title(method)) plt.figure('iters') plt.xlabel('$N$') plt.ylabel('Initialization iterations') plt.legend(loc='best').get_frame().set_alpha(0.25) plt.tight_layout(pad=0.2) plt.savefig("figs/periodic-ww%02.0f-ff%02.0f-scaling.pdf" % (ww * 100, ff * 100))
for fname in paths: print() start_fname = time.process_time() base = fname[:-8] method = base[:base.find('-')] energy_boundaries, mean_e, my_lnw, my_system, p_exc = compute.read_file(base) # Create a function for the entropy l_function, eee, sss = compute.linear_entropy(energy_boundaries, mean_e, my_lnw) plt.figure('latest-entropy') #plt.plot(E, normalize_S(l_function(E)), label=base) if method in {'wl','itwl','sad'}: plt.plot(E, normalize_S(l_function(E)), label=base, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=100) elif method == 'z': plt.plot(E, normalize_S(l_function(E)), label=base, color = styles.color(base), linestyle= styles.linestyle(base)) plt.figure('latest heat capacity') heat_capacity.plot(l_function, fname=fname,ax=ax, axins=axins) # correct_Cv = [heat_capacity.C(t,l_function) for t in T] # if method in {'wl','itwl','sad'}: # plt.plot(T, correct_Cv, label=base, marker = markers[precision], color = colors[method], linestyle= linestyles[method], markevery=5) # elif method == 'z': # plt.plot(T, correct_Cv, label=base, color = colors[method], linestyle= linestyles[method]) start_well_histogram = time.process_time() plt.figure('fraction-well') mean_which = np.loadtxt(f'{base}-which.dat') plt.plot(mean_e, mean_which, label=base)
base)[0] if method == 'tem': label = r'TEM' + r'-$E_{barr}$=0.' + styles.get_barrier( base)[0] fname = tail + 'seed-' + str(seed) + front data = np.load(fname) for k in data.keys(): print(k) E = data['E'] error_dist = data['error_dist_S'] plt.figure('Entropy error distribution') plt.plot(E, error_dist, label=label, marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=75) plt.figure('Canonical error incorrect peak') plt.plot(data['E_dist'], data['can_error_low_T'], label=label, marker=styles.marker(base), color=styles.color(base), linestyle=styles.linestyle(base), markevery=75) plt.figure('Canonical error phase transition') plt.plot(data['E_dist'], data['can_error_high_t'], label=label, marker=styles.marker(base),
def _plot_from_data(self, ax, axins, fname, data=None, data_bounds=None, subplot = None, dump_into_thesis = None): if data is None: data = self._query_fname(fname) if data_bounds is not None: lower_data, upper_data = data_bounds base = fname[:-4] method = os.path.split(fname)[-1].split('+')[0] print(method) if method == 'itwl': label = r'$1/t$-WL' + r'-$E_{barr}$=0.'+styles.get_barrier(base)[0] if method == 'sad': label = r'SAD' + r'-$E_{barr}$=0.'+styles.get_barrier(base)[0] if method == 'z': label = r'ZMC' + r'-$E_{barr}$=0.'+styles.get_barrier(base)[0] if method == 'tem': label = r'TEM' + r'-$E_{barr}$=0.'+styles.get_barrier(base)[0] if method in {'wl','itwl','sad', 'z'}: plt.figure('fraction-well') plt.plot(data['mean_e'], data['mean_which'], label=label) if len(data['hist']) != 0: plt.figure('histogram') plt.plot(data['mean_e'], data['hist'], label=label) plt.figure('latest-entropy') plt.plot(data['E'][:len(data['S'])], data['S'], label=label, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=25) plt.figure('convergence') plt.loglog(data['moves'], data['errors_S'], label=label, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=4) elif method == 'z': plt.plot(data['E'], data['S'], label=label, color = styles.color(base), linestyle= styles.linestyle(base)) if data_bounds is not None: plt.fill_between(lower_data['moves'], lower_data['errors_S'], upper_data['errors_S'], color = styles.color(base), linestyle=styles.linestyle(base), linewidth = 2, alpha = 0.2) heat_capacity.plot_from_data(data['T'][:len(data['C'])], data['C'], fname=fname, ax=ax, axins=axins) plt.figure('convergence-heat-capacity') plt.loglog(data['moves'], data['errors_C'], label=label, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=4) if data_bounds is not None: plt.fill_between(lower_data['moves'], lower_data['errors_C'], upper_data['errors_C'], color = styles.color(base), alpha = 0.2) if False:#subplot is not None: axs = subplot[0] axins_subplot = subplot[1] if method in {'wl','itwl','sad'}: axs['(c)'].plot(data['E'][:len(data['S'])], data['S'], label=label, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=250) elif method == 'z': axs['(c)'].plot(data['E'], data['S'], label=label, color = styles.color(base), linestyle= styles.linestyle(base)) heat_capacity.plot_from_data(data['T'][:len(data['C'])], data['C'], fname=fname, ax=axs['(d)'], axins=axins_subplot) plt.figure('convergence') if method in {'wl','itwl','sad'}: axs['(a)'].loglog(data['moves'], data['errors_S'], label=label, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=2) elif method == 'z': axs['(a)'].loglog(data['moves'], data['errors_S'], label=label, color = styles.color(base), linestyle= styles.linestyle(base), linewidth = 3) if data_bounds is not None: axs['(a)'].fill_between(lower_data['moves'], lower_data['errors_S'], upper_data['errors_S'], color = styles.color(base), linestyle=styles.linestyle(base), linewidth = 2, alpha = 0.2) plt.figure('convergence-heat-capacity') if method in {'wl','itwl','sad'}: axs['(b)'].loglog(data['moves'], data['errors_C'], label=label, marker = styles.marker(base), color = styles.color(base), linestyle= styles.linestyle(base), markevery=2) elif method == 'z': axs['(b)'].loglog(data['moves'], data['errors_C'], label=label, color = styles.color(base), linestyle= styles.linestyle(base), linewidth = 3) if data_bounds is not None: axs['(b)'].fill_between(lower_data['moves'], lower_data['errors_C'], upper_data['errors_C'], color = styles.color(base), alpha = 0.2)
plt.ylabel(r'$\Delta U$') golden_u = t_u_cv_s[1] reference_error = mean_u_err(ww, ff, N, reference, golden_u) if reference_error == None: continue print(' ', reference, reference_error) for method in methods: plt.figure(2) method_err = mean_u_err(ww, ff, N, method, golden_u) if method_err != None: print(' ', method, method_err) plt.figure(1) if method not in labels_added: plt.loglog(reference_error, method_err, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method), label=styles.title(method)) labels_added |= {method} else: plt.loglog(reference_error, method_err, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method)) plt.figure(2) plt.figure(2) plt.legend(loc='best') plt.savefig( 'figs/energy-for-debugging-ww%04.2f-ff%04.2f-N%i.pdf' % (ww, ff, N)) min_T = 0.2 # FIXME maybe shouldn't hardcode this? plt.figure(1) xmin, xmax = plt.xlim()
plt.ylabel(r'$\Delta U$') golden_u = t_u_cv_s[1] reference_error = mean_u_err(ww, ff, N, reference, golden_u) if reference_error == None: continue print ' ', reference, reference_error for method in methods: plt.figure(2) method_err = mean_u_err(ww, ff, N, method, golden_u) if method_err != None: print ' ', method, method_err plt.figure(1) if method not in labels_added: plt.loglog(reference_error, method_err, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method), label=styles.title(method)) labels_added |= set([method]) else: plt.loglog(reference_error, method_err, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method)) plt.figure(2) plt.figure(2) plt.legend(loc='best') plt.savefig( 'figs/energy-for-debugging-ww%04.2f-ff%04.2f-N%i.pdf' % (ww, ff, N)) min_T = 0.2 # FIXME maybe shouldn't hardcode this? plt.figure(1) xmin,xmax = plt.xlim()
log10_dos -= log10_dos.max() return energy, e_hist, log10w, log10_dos for method in methods: wildfilename = "../data/s%03d/periodic-ww%04.2f-ff%04.2f-N%i-%s-%%s.dat" \ % (seed, ww, ff, N, method) energy, e_hist, log10w, log10_dos = get_arrays(wildfilename) if method != 'wang_landau': plt.figure('dos-poster') plt.plot(energy, log10_dos, styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method), label=styles.title(method)) for ax in [ ax_dos, ax_dos_all ]: ax.plot(energy[log10_dos > -cap], log10_dos[log10_dos > -cap], styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method), label=styles.title(method)) for ax in [ ax_hist, ax_hist_all ]: ax.semilogy(energy, e_hist[:,1], styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method), label=styles.title(method)) for ax in [ ax_lnw, ax_lnw_all ]: ax.plot(energy[log10w < cap], log10w[log10w < cap], styles.dots(method), markerfacecolor='none', markeredgecolor=styles.color(method),
methods.remove(reference) plt.figure("u", figsize=fig_size) plt.figure("cv", figsize=fig_size) plt.figure("s", figsize=fig_size) for n in range(len(Ns)): for method in methods: plt.figure("u") plt.loglog( u_errors[reference][n], u_errors[method][n], styles.dots(method), markerfacecolor="none", markeredgecolor=styles.color(method), label=styles.title(method), ) plt.figure("cv") plt.loglog( cv_errors[reference][n], cv_errors[method][n], styles.dots(method), markerfacecolor="none", markeredgecolor=styles.color(method), label=styles.title(method), ) plt.figure("s") plt.loglog( s_errors[reference][n], s_errors[method][n],