-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_synthetic_target.jl
67 lines (56 loc) · 1.39 KB
/
make_synthetic_target.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
using PolyaUrnSimulator
using StatsBase
using ProgressMeter
include("lib/history2vec.jl")
function run_existing_model(rho::Int, nu::Int, s::String)
_s::Union{Function,Nothing} = nothing
if s == "SSW"
_s = ssw_strategy!
elseif s == "WSW"
_s = wsw_strategy!
else
throw(error("strategy must be SSW or WSW"))
end
env = Environment()
init_agents = [
Agent(rho, nu, _s)
Agent(rho, nu, _s)
]
init!(env, init_agents)
for _ in 1:20000
step!(env)
end
return history2vec(env.history, 1000)
end
function synthetic_target()
outdir = mkpath("data")
outfile = "$outdir/synthetic_target.csv"
open(outfile, "w") do fp
println(fp, "rho,nu,s,gamma,no,nc,oo,oc,c,y,g,r,h")
end
N = 1:10
parameter_sets = [
Dict("rho" => 5, "nu" => 15),
Dict("rho" => 20, "nu" => 7),
Dict("rho" => 5, "nu" => 5)
]
ss = ["SSW", "WSW"]
p = Progress(length(N) * length(parameter_sets) * length(ss))
lk = ReentrantLock()
Threads.@threads for _ in N
Threads.@threads for parameter_set in parameter_sets
Threads.@threads for s in ss
rho = parameter_set["rho"]
nu = parameter_set["nu"]
res = run_existing_model(rho, nu, s)
lock(lk) do
open(outfile, "a") do fp
println(fp, join(string.(values((; rho, nu, s, res...))), ","))
end
end
next!(p)
end
end
end
end
synthetic_target()