Commit f2183658 authored by Hippalectryon's avatar Hippalectryon

update dimension fit

parent 63f52135
......@@ -245,8 +245,8 @@ class Processor:
[np.mean(group_dimensions) for group_dimensions in group_dimensions_combined])
# avg fit
def fit(x, a1):
return x**a1
def fit(x, a1, b1):
return b1*x**a1
group_dimension_avg = np.array(self.data_holders["group_hulls_dimensions_avg"][-1])
size_x = np.array(range(len(group_dimension_avg)))
......@@ -256,13 +256,13 @@ class Processor:
group_dimension_avg = group_dimension_avg[nonzero_indexes]
size_x = size_x[nonzero_indexes]
popt, _ = scipy.optimize.curve_fit(fit, size_x, group_dimension_avg)
a, = popt
a, b = popt
residuals = group_dimension_avg - fit(size_x, a)
residuals = group_dimension_avg - fit(size_x, a, b)
ss_res = np.sum(residuals ** 2)
ss_tot = np.sum((group_dimension_avg - np.mean(group_dimension_avg)) ** 2)
r_squared = 1 - (ss_res / ss_tot)
self.data_holders["group_hulls_dimensions_avg_fit"].append([a, r_squared])
self.data_holders["group_hulls_dimensions_avg_fit"].append([a, b, r_squared])
except Exception as e:
log.warning("Exception in group dimensions fit: %s" % e)
self.data_holders["group_hulls_dimensions_avg_fit"].append(None)
......
......@@ -403,16 +403,16 @@ class Visualiser:
self.layout_artists["group_dimension_avg"].set_data(range(3, len(hull_dimensions)), hull_dimensions[3:])
def plot_group_dimension_avg_fit(self, frame_num: int) -> None:
def fit(x, a1):
return x ** a1
def fit(x, a1, b1):
return b1 * x ** a1
data = self.processed_data["group_hulls_dimensions_avg_fit"][frame_num]
if data is None:
return
a, r_squared = data
a, b, r_squared = data
x_data = np.array(range(len(self.processed_data["group_hulls_dimensions_avg"][frame_num]) + 1))
self.layout_artists["group_dimension_avg_fit"].set_data(x_data, fit(x_data, a))
self.layout_artists["group_dimension_text"].set_text("$R^2$ = %.5f\n $x^a$: a=%.2f" % (r_squared, a))
self.layout_artists["group_dimension_avg_fit"].set_data(x_data, fit(x_data, a, b))
self.layout_artists["group_dimension_text"].set_text("$R^2$ = %.5f\n $bx^a$: a=%.2f" % (r_squared, a))
def plot_evolution_group_size(self, frame_num: int) -> None:
times = self.timestamps[:frame_num + 1]
......
......@@ -38,22 +38,22 @@ def launch_two_groups(output_file: str, L: float, n_birds_1: int, n_birds_2: int
Life.simulate(physics, dt, total_time, verbose_prop=.1, output_file=output_file)
# launch_simulation_random("simulation_data/test.json", L=100, n_birds=1000, eta=.3, total_time=50) # , evolve=evolve)
# launch_two_groups("simulation_data/test.json", L=100, n_birds_1=100, n_birds_2=0, radius_1=5, radius_2=5,
# total_time=60, center_1=[50, 50], center_2=[80, 50], angle_1=0, angle_2=np.pi, eta=.4)
# launch_simulation_random("simulation_data/test.json", L=70, n_birds=1000, eta=.3, total_time=500) # , evolve=evolve)
#
# # launch_two_groups("simulation_data/test.json", L=100, n_birds_1=100, n_birds_2=0, radius_1=5, radius_2=5,
# # total_time=60, center_1=[50, 50], center_2=[80, 50], angle_1=0, angle_2=np.pi, eta=.4)
# to_process = ["avg_speed", "avg_angle", "group_size", "group_size_avg", "group_size_avg_fit", "groups", "correlations",
# "correlations_fit", "group_to_size", "group_hulls"]
# Processor().process("simulation_data/test.json", "processing_data/test", verbose_prop=.1, to_process=to_process,
# options={"correlations_stochastic_points": 5000})
to_process = ["avg_speed", "avg_angle", "group_size", "group_size_avg", "group_size_avg_fit", "groups", "correlations",
"correlations_fit", "group_to_size", "group_hulls"]
Processor().process("simulation_data/test.json", "processing_data/test", verbose_prop=.1, to_process=to_process,
options={"correlations_stochastic_points": 5000})
to_draw = ["avg_speed", "avg_angle", "avg_polar", "correlations", "correlations_fit", "correlation_length",
"group_size", "group_size_avg", "group_size_avg_fit", "group_dimension", "group_dimension_avg", "quiver", "evolution_group_size"]
Visualiser("processing_data/test", "visualisations/test.mp4", simulation_data_file="simulation_data/test.json",
verbose_prop=.1,
to_draw=to_draw, t_start=0,
to_draw=to_draw,
options={"quiver_color_by_group": True, "quiver_draw_by_group": True, "quiver_color_single": True, "max_group_size": 50,
"max_num_groups": 500}).vizualize()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment