From f452301f0ade4d8da0c66180d7f9c1e0f2b67c0c Mon Sep 17 00:00:00 2001 From: Kenneth Jao Date: Sun, 19 Sep 2021 02:59:09 -0400 Subject: [PATCH] Changed edge counting and added defect diagrams --- shrink_energy_comparison.py | 40 ++++++++++++++++++++++++++++--------- simulation.py | 2 -- src/voronoi_dcel.pyx | 8 ++++---- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/shrink_energy_comparison.py b/shrink_energy_comparison.py index bf3c633..7ad77c4 100644 --- a/shrink_energy_comparison.py +++ b/shrink_energy_comparison.py @@ -67,13 +67,20 @@ def get_equilibria_data(filepath: Path): sim = Simulation.load(file) data["all"][sim.w] = [] for frame in sim.frames: - data["all"][sim.w].append([frame.energy, np.var(frame.stats["avg_radius"]) <= 1e-8]) + data["all"][sim.w].append([ + frame.energy, + np.var(frame.stats["avg_radius"]) <= 1e-8, + np.count_nonzero(frame.stats["site_edge_count"] != 6) + ]) sim.get_distinct() data["distinct"][sim.w] = [] for frame in sim.frames: - data["distinct"][sim.w].append([frame.energy, - np.var(frame.stats["avg_radius"]) <= 1e-8]) + data["distinct"][sim.w].append([ + frame.energy, + np.var(frame.stats["avg_radius"]) <= 1e-8, + np.count_nonzero(frame.stats["site_edge_count"] != 6) + ]) hashes = int(21*i/len(files)) print(f'Loading simulations... |{"#"*hashes}{" "*(20-hashes)}|' + \ @@ -95,7 +102,7 @@ def axis_settings(ax, widths): ax.grid(zorder=0) ax.set_xticks([round(w,2) for w in widths[::-2]]) ax.set_xticklabels(ax.get_xticks(), rotation = 90) - plt.subplots_adjust(.05, .12, .97, .9) + plt.subplots_adjust(.07, .12, .97, .9) def main(): @@ -119,7 +126,7 @@ def main(): # Torus minimum energies used as reference. - # Basin of attraction diagram. + # Probability of disorder diagram. fig, ax = plt.subplots(figsize=(16, 8)) all_disorder_count = [] for width in widths: @@ -129,12 +136,12 @@ def main(): ax.plot(widths, all_disorder_count) axis_settings(ax, widths) ax.yaxis.set_major_formatter(mtick.PercentFormatter()) - ax.title.set_text('Basin of Attraction') + ax.title.set_text('Probability of Disorder') ax.set_xlabel("Width") ax.set_ylabel("Disordered Equilibria") boa_y_min = round(min(all_disorder_count)/20)*20 - 5 ax.set_yticks(np.arange(boa_y_min, 100.01, 2.5)) - fig.savefig(fig_folder / "Basin of Attraction.png") + fig.savefig(fig_folder / "Probability of Disorder.png") # Density of States diagram. @@ -156,6 +163,21 @@ def main(): ax.set_yticks(np.arange(0, dos_y_max, round(dos_y_max/200, 1)*10)) fig.savefig(fig_folder / "Density Of States.png") + # Defect density diagram + fig, ax = plt.subplots(figsize=(16, 8)) + + defects = [] + for width in widths: + defects.append(sum([c[2] for c in data["all"][width] if not c[1]])/len(data["all"][width])) + + ax.plot(widths, defects) + axis_settings(ax, widths) + ax.title.set_text('Average Defects') + ax.set_xlabel("Width") + ax.set_ylabel("Defects") + ax.set_yticks(np.arange(0, 1+max(defects), 0.5)) + fig.savefig(fig_folder / "Defects.png") + # Bifurcation diagram fig, ax = plt.subplots(figsize=(16, 8)) @@ -215,8 +237,8 @@ def main(): ax.set_xlabel("Width") ax.set_ylabel("Reduced Energy") bif_y_max = np.max(np.abs(np.concatenate((min_unorder_off, max_unorder_off)))) - ax.set_yticks(np.arange(-bif_y_max, bif_y_max, round(bif_y_max/20, \ - -math.floor(math.log10(bif_y_max/20))))) + bif_top = np.arange(0, bif_y_max, round(bif_y_max/20, -math.floor(math.log10(bif_y_max/20)))) + ax.set_yticks(np.concatenate((-bif_top[1:][::-1], bif_top))) fig.savefig(fig_folder / "Bifurcation.png") print(f"Wrote to {fig_folder}.") diff --git a/simulation.py b/simulation.py index 94b4617..6857485 100644 --- a/simulation.py +++ b/simulation.py @@ -735,5 +735,3 @@ class Shrink(Simulation): self.w -= self.w_change del self.frames[0] - -TravelEQ = Search \ No newline at end of file diff --git a/src/voronoi_dcel.pyx b/src/voronoi_dcel.pyx index 7b489ac..09281e0 100644 --- a/src/voronoi_dcel.pyx +++ b/src/voronoi_dcel.pyx @@ -622,10 +622,10 @@ cdef class VoronoiContainer: cache = self.site_cache[:self.n, :] self.stats["site_areas"] = np.asarray(cache[:, SITE_CACHE_MAP.iarea]) - edge_count = np.empty((self.n,)) - for i in range(self.n): - edge_count[i] = len(self.vor_data.regions[self.vor_data.point_region[i]]) - self.stats["site_edge_count"] = edge_count + #edge_count = self.sites[:, 2]np.empty((self.n,)) + # for i in range(self.n): + # edge_count[i] = len(self.vor_data.regions[self.vor_data.point_region[i]]) + self.stats["site_edge_count"] = self.sites[:self.n, 2] self.stats["site_isos"] = np.asarray(cache[:, SITE_CACHE_MAP.iisoparam]) self.stats["site_energies"] = np.asarray(cache[:, SITE_CACHE_MAP.ienergy])