-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrunMe.jl
189 lines (146 loc) · 5.85 KB
/
runMe.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# The [Neherlab COVID-19](https://neherlab.org/covid19/) forecast model
# Runs with 4 processes (if 4 cores CPU) - Only for optimised libraries
#using Distributed
#TOTAL_PROCS = 4
#Distributed.addprocs(TOTAL_PROCS - Distributed.nprocs())
include("COVID-19-parameters.jl")
include("COVID-19-utils.jl")
include("COVID-19-model.jl")
include("COVID-19-run-model.jl")
include("COVID-19-data.jl")
PRINT_DEBUG = false
using BlackBoxOptim
# Global variable that holds the optimised disease parameters
DiseaseParameters = DISEASE_INIT
# If running for the first time, or no updates for a long time
# updateData()
#------------------------------------------------------------------------------------------------
#-- FOR DEBUGGING RUNS
# COUNTRY_LIST = [
# ("France", :north),
# ("Italy", :north),
# ("Spain", :north),
# ("United Kingdom", :north)]
# The list is focused on Europe
COUNTRY_LIST = [
("Austria", :north),
("Belgium", :north),
("Bulgaria", :north),
("Denmark", :north),
("France", :north),
("Germany", :north),
("Greece", :north),
("Italy", :north),
("Netherlands", :north),
("Norway", :north),
("Poland", :north),
("Spain", :north),
("Sweden", :north),
("United_Kingdom", :north),
# ("United_States_of_America", :north)
]
countryData = Dict( c => populateCountryData(c, h, useOptimised = false) for (c, h) in COUNTRY_LIST)
plt = plotVignette()
using FileIO, Plots, ImageIO
Plots.savefig(plt, "Vignette1.png")
plotCountriestoDisk("__beforeOptim")
saveParameters()
# Print only 3 decimals
using Printf
Base.show(io::IO, f::Float64) = @printf(io, "%1.3f", f)
#-------------------------------------------------------------------------------------------------
#--
#-- First calibration
#--
updateEveryCountry(;maxtime = 20)
updateEpidemiologyOnce(maxtime = 120)
plt = plotVignette()
Plots.savefig(plt, "Vignette2.png")
plotCountriestoDisk("__first_calib")
saveParameters()
#-------------------------------------------------------------------------------------------------
#--
#-- Runs of all-country optim - disease parameters
#--
N_RUNS = 4
for run in 1:N_RUNS
#-------------------------------------------------------------------------------------------------
#--
#-- Optimisition all countries at once
#-- Build a vector of all the countries' parameters with start date constraints
fullRange = empty([(0.0, 0.0)])
for (c1, _) in COUNTRY_LIST
countryRange = COUNTRY_RANGE
countryRange[COUNTRY_PARAM_START] = approximateModelStartRange(c1)
fullRange = vcat(fullRange, countryRange)
end
#-- Optimise
best = best_candidate(bboptimize(sumCountryLossesCountries,
SearchRange = fullRange;
Method = :adaptive_de_rand_1_bin,
MaxTime = 180,
TargetFitness = 2.0,
NThreads = Threads.nthreads(),
TraceMode = :compact))
#-- Store the optimised parameters
for i in 1:COUNTRY_N
country, _ = COUNTRY_LIST[i]
country_start_index = (i - 1) * COUNTRY_N + 1
country_final_index = (i - 1) * COUNTRY_N + COUNTRY_N
global countryData[country][:params] = best[country_start_index:country_final_index]
end
#-------------------------------------------------------------------------------------------------
# Update Epidemiology
updateEpidemiologyOnce(maxtime = 60)
#-------------------------------------------------------------------------------------------------
# Outputs
saveParameters()
plotCountriestoDisk(repr(now()));
end
plotVignette()
#-------------------------------------------------------------------------------------------------
# Normal runs: Optimise country, then disease after each country
N_RUNS = 10
for run in 1:N_RUNS
println(); println("OPTIMISING THE WORST HALF OF COUNTRIES BY AVERAGE ERRORS---------------------------")
scores = allSingleLosses(sorted = true)
@show scores
for c1 in first(scores, COUNTRY_N ÷ 3)[:, 2]
updateCountryOnce(c1; maxtime = 60)
end
# After having done all the countries, epidemiology again more seriously
updateEpidemiologyOnce(; maxtime = 60)
println()
saveParameters()
plotCountriestoDisk(repr(now()))
end
plotVignette()
#-------------------------------------------------------------------------------------------------
#--
#-- Global optimisation: all countries at once + disease parameters.
#--
fullRange = empty([(0.0, 0.0)])
for (c1, _) in COUNTRY_LIST
countryRange = COUNTRY_RANGE
countryRange[COUNTRY_PARAM_START] = approximateModelStartRange(c1)
global fullRange = vcat(fullRange, countryRange)
end
fullRange = vcat(DISEASE_RANGE, fullRange)
result = bboptimize(fullEpidemyLoss,
SearchRange = fullRange;
Method = :adaptive_de_rand_1_bin,
MaxTime = 300,
TargetFitness = 2.0,
NThreads = Threads.nthreads(),
TraceMode = :compact)
best = best_candidate(result)
DiseaseParameters = best[1:DISEASE_N]
for i in 1:COUNTRY_LIST_N
country, _ = COUNTRY_LIST[i]
country_start_index = DISEASE_N + (i - 1) * COUNTRY_N + 1
country_final_index = DISEASE_N + (i - 1) * COUNTRY_N + COUNTRY_N
global countryData[country][:params] = best[country_start_index:country_final_index]
end
plotVignette()
saveParameters()
plotCountriestoDisk(repr(now()));