Skip to content

Commit 6cfe755

Browse files
committed
Updated simulations Kiel
1 parent e586aea commit 6cfe755

5 files changed

+240
-20
lines changed

exploration.ipynb

+201-13
Large diffs are not rendered by default.

img/metapopulation_stepping-stone.odg

21.5 KB
Binary file not shown.

img/metapopulation_stepping-stone.png

61.9 KB
Loading

plotting.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def plot_comparison_gini_pulses(dataset_1, dataset_2, title, legend_1, legend_2,
103103
dataset_1_local = pd.read_csv(f"{dataset_1}_subpop_gini.csv", index_col=0)
104104
dataset_2_local = pd.read_csv(f"{dataset_2}_subpop_gini.csv", index_col=0)
105105

106-
107106
line1, = plt.plot(dataset_1_local.mean(axis=1), color = 'xkcd:sky blue', label=f"{legend_1} subpop avg")
108107
line2, = plt.plot(dataset_2_local.mean(axis=1), color = 'tan', label=f"{legend_2} subpop avg")
109108
plt.fill_between(dataset_1_local.index, dataset_1_local.mean(axis=1) - dataset_1_local.std(axis=1), dataset_1_local.mean(axis=1) + dataset_1_local.std(axis=1), color='xkcd:sky blue', alpha=0.3)
@@ -130,4 +129,34 @@ def plot_comparison_gini_pulses(dataset_1, dataset_2, title, legend_1, legend_2,
130129
plt.grid(linestyle=':', linewidth=0.5)
131130
plt.title(title)
132131

133-
plt.savefig(output_file)
132+
plt.savefig(output_file)
133+
134+
135+
def plot_subpopulation_mean(dataset, subpop_id, output_file, number_of_pulses = 5, length_of_pulses = 1, settling_period = 99):
136+
# deme = pd.Series(dataset[dataset["Replicate"] == 0][f"{subpop_id}"])
137+
for replicate in dataset["Replicate"].unique():
138+
if replicate == 0:
139+
deme = pd.Series(dataset[dataset["Replicate"] == replicate][f"{subpop_id}"])
140+
141+
deme = pd.concat([deme, pd.Series(dataset[dataset["Replicate"] == replicate][f"{subpop_id}"])], axis=1)
142+
143+
fig = plt.plot(deme.mean(axis=1), color="tab:orange")
144+
std_plus = deme.mean(axis=1) + deme.std(axis=1)
145+
std_minus = deme.mean(axis=1) - deme.std(axis=1)
146+
# std_plus cannot be larger than 100 in the beginning (but values can as it can be below 0 and this is a symetric +/-!)
147+
std_plus[std_plus > 100] = 100
148+
std_minus[std_minus < 0] = 0
149+
plt.fill_between(deme.index, std_minus, std_plus, alpha = 0.3, color="tab:orange")
150+
plt.ylabel("Individuals with extra trait")
151+
plt.xlabel("Generations (x100)")
152+
plt.ylim([0, 100])
153+
plt.grid(linestyle=':', linewidth=0.5)
154+
plt.title(f"Extra trait in subpopulation {subpop_id}")
155+
156+
plt.axvline(500, color="black", linestyle='--', ymax=1)
157+
for i in range(1, number_of_pulses + 1):
158+
plt.axvline(500 + i*(length_of_pulses + settling_period), color="dimgrey", linestyle='--', ymax=1)
159+
160+
plt.savefig(output_file)
161+
162+
return fig, deme

script_Kiel2025_spread.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
measure_timing = 100
1111

1212
total_population = 800
13-
replicates = 1
13+
replicates = 50
1414
save_output = True
15-
interactions = ['neutral_interaction'] # 'axelrod_interaction'
15+
interactions = ['axelrod_interaction'] # 'axelrod_interaction'
1616
number_of_subpopulations = 8
1717
migration_rates = [0.0001]
1818
mutation_rates = 0.0005
1919

2020
burn_in = 50000
21-
pulse_length = 0
21+
pulse_length = 100
2222
number_of_pulses = 5
2323
settling_period = 10000 - pulse_length # 10000
2424

2525
start_time = time.time()
2626

2727
count = 0
2828

29-
title = "frontConnection"
29+
title = "singleConnection"
3030
migration_config = np.genfromtxt(f"./configs/maritime_configs/{title}.csv", delimiter=",")
3131

3232
for interaction in interactions:
@@ -104,7 +104,10 @@
104104

105105
t += 1
106106

107-
extra_traits_counts_df = pd.concat([extra_traits_counts_df, pd.Series(extra_traits_in_metapopulation, name=replicate_id)], axis=1)
107+
current_df = pd.DataFrame(extra_traits_in_metapopulation)
108+
current_df['Replicate'] = replicate_id
109+
extra_traits_counts_df = pd.concat([extra_traits_counts_df, current_df])
110+
108111

109112
if verbose:
110113
print(f"Generation reached: {t}")

0 commit comments

Comments
 (0)