From 83468938bbbec33f15a3a4d77e03c8c1849d76b9 Mon Sep 17 00:00:00 2001 From: Cory Date: Sun, 3 Dec 2023 16:42:50 +0100 Subject: [PATCH] Formatting --- python_scripts/burn_in_time.py | 25 +++++++++++----------- python_scripts/pd_estimate.py | 33 ++++++++++++++++++++---------- python_scripts/phase_transition.py | 19 +++++++++++------ python_scripts/test_burn_in.py | 17 ++++++++------- python_scripts/timing.py | 21 ++++++++----------- 5 files changed, 63 insertions(+), 52 deletions(-) diff --git a/python_scripts/burn_in_time.py b/python_scripts/burn_in_time.py index 0a6c90f..29160f1 100644 --- a/python_scripts/burn_in_time.py +++ b/python_scripts/burn_in_time.py @@ -4,35 +4,29 @@ import seaborn as sns sns.set_theme() params = { "font.family": "Serif", - "font.serif": "Roman", + "font.serif": "Roman", "text.usetex": True, "axes.titlesize": "large", "axes.labelsize": "large", "xtick.labelsize": "large", "ytick.labelsize": "large", - "legend.fontsize": "medium" + "legend.fontsize": "medium", } plt.rcParams.update(params) + def plot_from_file(): files = [ - # "output/burn_in_time/unordered_1_0_1421110368.txt", - # "output/burn_in_time/ordered_1_0_611577739.txt", - "output/burn_in_time/unordered_2_4_1212892317.txt", - "output/burn_in_time/ordered_2_4_2408603856.txt", + "data/hp/burn_in_time/unordered_2_4_1212892317.txt", + "data/hp/burn_in_time/ordered_2_4_2408603856.txt", ] labels = [ "Unordered", "Ordered", - # "2.4, unordered", - # "2.4, ordered" ] colors = [ "darkred", "seagreen", - # "steelblue", - # "darkred", - # "darkgoldenrod", ] fig1, ax1 = plt.subplots() @@ -57,14 +51,19 @@ def plot_from_file(): ax1.set_xlabel("t") ax1.set_ylabel(r"$\langle \epsilon \rangle$") ax1.legend(title="Initial state", loc="upper right") - fig1.savefig("../latex/images/burn_in_time_energy_2_4.pdf", bbox_inches="tight") + + fig1.savefig("./latex/images/burn_in_time_energy_2_4.pdf", bbox_inches="tight") ax2.set_ylabel(r"$\langle |m| \rangle$") ax2.set_xlabel("t") ax2.legend(title="Initial state", loc="upper right") - fig2.savefig("../latex/images/burn_in_time_magnetization_2_4.pdf", bbox_inches="tight") + fig2.savefig( + "./latex/images/burn_in_time_magnetization_2_4.pdf", bbox_inches="tight" + ) + def main(): plot_from_file() + if __name__ == "__main__": main() diff --git a/python_scripts/pd_estimate.py b/python_scripts/pd_estimate.py index 881b79d..b1508c6 100644 --- a/python_scripts/pd_estimate.py +++ b/python_scripts/pd_estimate.py @@ -1,4 +1,4 @@ -import os +from os import makedirs from pathlib import Path import matplotlib.pyplot as plt @@ -9,20 +9,20 @@ from scipy.stats import norm sns.set_theme() params = { "font.family": "Serif", - "font.serif": "Roman", + "font.serif": "Roman", "text.usetex": True, "axes.titlesize": "large", "axes.labelsize": "large", "xtick.labelsize": "large", "ytick.labelsize": "large", - "legend.fontsize": "medium" + "legend.fontsize": "medium", } plt.rcParams.update(params) def plot(infile, outfile): if not (outdir := Path(outfile).parent).exists(): - os.makedirs(outdir) + makedirs(outdir) figure1, ax1 = plt.subplots() eps = [] @@ -32,21 +32,32 @@ def plot(infile, outfile): vals = line.strip().split(",") eps.append(float(vals[0])) - ax1.hist(eps, np.arange(min(eps), max(eps) + 0.02, 0.02), color="steelblue", density=True, ec="white", lw=0.2) + ax1.hist( + eps, + np.arange(min(eps), max(eps) + 0.02, 0.02), + color="steelblue", + density=True, + ec="white", + lw=0.2, + ) ax1.set_xlabel(r"$\epsilon$") ax1.set_ylabel("Density") - mu, sigma = np.mean(eps), np.std(eps) + mu, sigma = np.mean(eps), np.std(eps) x = np.arange(min(eps), max(eps) + 0.02, 0.02) - stats = (f"$\\langle \\epsilon \\rangle$ = {np.mean(eps):.4f}\n" - f"Var$(\\epsilon)$ = {np.var(eps):.4f}") + stats = ( + f"$\\langle \\epsilon \\rangle$ = {np.mean(eps):.4f}\n" + f"Var$(\\epsilon)$ = {np.var(eps):.4f}" + ) bbox = dict(boxstyle="round", pad=0.3, fc="white", ec="white", alpha=0.5) - ax1.text(0.95, 0.9, stats, bbox=bbox, transform=ax1.transAxes, ha="right", va="center") + ax1.text( + 0.95, 0.9, stats, bbox=bbox, transform=ax1.transAxes, ha="right", va="center" + ) ax1.plot(x, norm.pdf(x, mu, sigma), color="mediumseagreen") figure1.savefig(outfile, bbox_inches="tight") if __name__ == "__main__": - plot("output/pd_estimate/estimate_1_0.txt", "../latex/images/pd_estimate_1_0.pdf") - plot("output/pd_estimate/estimate_2_4.txt", "../latex/images/pd_estimate_2_4.pdf") + plot("./data/hp/pd_estimate/estimate_1_0.txt", "./latex/images/pd_estimate_1_0.pdf") + plot("./data/hp/pd_estimate/estimate_2_4.txt", "./latex/images/pd_estimate_2_4.pdf") diff --git a/python_scripts/phase_transition.py b/python_scripts/phase_transition.py index 7751254..c8186ca 100644 --- a/python_scripts/phase_transition.py +++ b/python_scripts/phase_transition.py @@ -1,3 +1,4 @@ +from os import makedirs from pathlib import Path import matplotlib.pyplot as plt @@ -6,6 +7,9 @@ from scipy.stats import linregress def plot_phase_transition_alt(indir, outdir): + if not (path := Path(outdir)).exists(): + makedirs(path) + files = [ "size_20.txt", "size_40.txt", @@ -84,6 +88,9 @@ def plot_phase_transition_alt(indir, outdir): def plot_phase_transition(indir, outdir): + if not (path := Path(outdir)).exists(): + makedirs(path) + files = [ "size_20.txt", "size_40.txt", @@ -168,24 +175,24 @@ def plot_phase_transition(indir, outdir): if __name__ == "__main__": plot_phase_transition_alt( - "fox_output/phase_transition/wide/10M/", + "data/fox/phase_transition/wide/10M/", "latex/images/phase_transition/fox/wide/10M/", ) plot_phase_transition( - "fox_output/phase_transition/wide/1M/", + "data/fox/phase_transition/wide/1M/", "latex/images/phase_transition/fox/wide/1M/", ) plot_phase_transition( - "fox_output/phase_transition/narrow/10M/", + "data/fox/phase_transition/narrow/10M/", "latex/images/phase_transition/fox/narrow/10M/", ) plot_phase_transition( - "output/phase_transition/", "latex/images/phase_transition/hp/" + "data/hp/phase_transition/", "latex/images/phase_transition/hp/" ) plot_phase_transition( - "output/phase_transition/", "latex/images/phase_transition/hp/" + "data/hp/phase_transition/", "latex/images/phase_transition/hp/" ) plot_phase_transition( - "output/phase_transition/", + "data/hp/phase_transition/", "latex/images/phase_transition/hp/", ) diff --git a/python_scripts/test_burn_in.py b/python_scripts/test_burn_in.py index afb6728..6360cde 100644 --- a/python_scripts/test_burn_in.py +++ b/python_scripts/test_burn_in.py @@ -1,11 +1,13 @@ +from os import makedirs from pathlib import Path import matplotlib.pyplot as plt -import numpy as np -from scipy.stats import linregress -def plot_phase_transition(indir, outdir): +def plot(indir, outdir): + if not (path := Path(outdir)).exists(): + makedirs(path) + files = [ "no_burn_in.txt", "burn_in.txt", @@ -20,7 +22,6 @@ def plot_phase_transition(indir, outdir): figure3, ax3 = plt.subplots() figure4, ax4 = plt.subplots() - for file, label in zip(files, labels): t = [] e = [] @@ -38,13 +39,11 @@ def plot_phase_transition(indir, outdir): CV.append(float(l[3])) X.append(float(l[4])) - ax1.plot(t, e, label=label) ax2.plot(t, m, label=label) ax3.plot(t, CV, label=label) ax4.plot(t, X, label=label) - figure1.legend() figure2.legend() figure3.legend() @@ -62,7 +61,7 @@ def plot_phase_transition(indir, outdir): if __name__ == "__main__": - plot_phase_transition( - "output/test_burn_in_time/", - "../latex/images/test_burn_in", + plot( + "./data/hp/test_burn_in_time/", + "./latex/images/test_burn_in", ) diff --git a/python_scripts/timing.py b/python_scripts/timing.py index 61d17d4..bae1797 100644 --- a/python_scripts/timing.py +++ b/python_scripts/timing.py @@ -1,11 +1,13 @@ +from os import makedirs from pathlib import Path import matplotlib.pyplot as plt -import numpy as np -from scipy.stats import linregress def plot_timing(indir, outdir): + if not (path := Path(outdir)).exists(): + makedirs(path) + files = [ "lattice_sizes.txt", "sample_sizes.txt", @@ -14,14 +16,8 @@ def plot_timing(indir, outdir): "Lattice sizes", "Sample sizes", ] - xlabels = [ - "Lattice size", - "Sampling size" - ] - outfiles = [ - "lattice_size.pdf", - "sample_sizes.pdf" - ] + xlabels = ["Lattice size", "Sampling size"] + outfiles = ["lattice_size.pdf", "sample_sizes.pdf"] for file, label, xlabel, outfile in zip(files, labels, xlabels, outfiles): figure1, ax1 = plt.subplots() @@ -35,7 +31,6 @@ def plot_timing(indir, outdir): x.append(float(l[0])) t.append(float(l[1])) - ax1.plot(x, t, label=label) ax1.set_xlabel(xlabel) ax1.set_ylabel("time (seconds)") @@ -49,6 +44,6 @@ def plot_timing(indir, outdir): if __name__ == "__main__": plot_timing( - "output/timing/", - "../latex/images/timing", + "data/hp/timing/", + "./latex/images/timing", )