-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiments.jl
90 lines (80 loc) · 2.42 KB
/
experiments.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# %%
using DrWatson
@quickactivate
# %%
using DataFrames
include("./src/simple_model.jl")
using .SimpleModels
# %%
function run_exp(params::Dict; save=false)
@unpack n_iter = params
specie_mutation = Mutation(params["specie_mutation_probability"], params["specie_mutation_variance"])
specie = Specie(
params["specie_fecundity"],
params["specie_gamma"],
params["specie_plasticity"],
params["specie_selection"],
specie_mutation,
params["specie_migration"],
)
site_climate = SiteClimate(
params["site_climate_carrying"],
params["site_climate_inivalue"],
params["site_climate_variance"],
)
model = SimpleModel(specie, site_climate)
results = run!(model, params["n_iter"])
df = DataFrame(results)
df[!, "replicate"] = fill(params["replicate"], nrow(df))
df[!, "specie_plasticity"] = fill(params["specie_plasticity"], nrow(df))
df[!, "site_climate_variance"] = fill(params["site_climate_variance"], nrow(df))
if save
csv_filename = datadir("simple_model", savename(params, "csv"; accesses=["site_climate_variance", "specie_plasticity", "replicate"]))
wsave(csv_filename, df)
end
return params, df
end
# %%
allparams = Dict(
"n_iter" => 10_000,
"site_climate_variance" => [0.5, 0.8, 1.1, 1.2, 1.5, 2, 2.5],
"site_climate_carrying" => 80_000,
"site_climate_inivalue" => 50,
"specie_fecundity" => 20,
"specie_gamma" => 0.8,
"specie_plasticity" => [1000, 50, 1],
"specie_selection" => 1,
"specie_mutation_probability" => 0.01,
"specie_mutation_variance" => 0.1,
"specie_migration" => 0.0,
"replicate" => 1:10 |> collect,
)
dicts = dict_list(allparams);
results = Vector{Any}(undef, length(dicts))
Threads.@threads for i in 1:length(dicts)
results[i] = run_exp(dicts[i], save=true)
end
# %%
using AlgebraOfGraphics, CairoMakie, DataFramesMeta
# %%
dfs = getindex.(results, 2);
df = vcat(dfs...);
sort!(df, [:t, :specie_plasticity]);
# %%
resolution = (1000, 1000)
fig = Figure(; resolution)
specs = (
data(df)
* mapping(
:t, :var,
col=:specie_plasticity => nonnumeric,
row=:site_climate_variance => nonnumeric,
color=:replicate => nonnumeric,
)
* (
visual(Lines) * smooth()
)
)
colors = fill(:black, length(unique(df.replicate)))
draw!(fig, specs; facet=(; linkxaxes=:minimal, linkyaxes=:none), palettes=(color=colors,))
fig