Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffckerr committed May 18, 2021
1 parent af3f6a5 commit 56ab243
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Version 3.0.3 (2021-05-17)
--------------------------
- Added a new class, ``cv.Calibration``, that can perform automatic calibration. Simplest usage is ``sim.calibrate(calib_pars)``. Note: this requires Optuna, which is not installed by default; please install separately via ``pip install optuna``. See the updated calibration tutorial for more information.
- Added a new result, ``known_deaths``, which counts only deaths among people who have been diagnosed.
- Updated several vaccine and variant parameters (e.g., B1.351 and B117 cross-immunity).
- ``sim.compute_fit()`` now returns the fit by default, and creates ``sim.fit`` (previously, this was stored in ``sim.results.fit``).
- *Regression information*: Calls to ``sim.results.fit`` should be replaced with ``sim.fit``. The ``output`` parameter for ``sim.compute_fit()`` has been removed since it now always outputs the ``Fit`` object.
- *GitHub info*: PR `1047 <https://github.com/amath-idm/covasim/pull/1047>`__
Expand Down
14 changes: 11 additions & 3 deletions covasim/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,13 @@ def __init__(self, sim, calib_pars=None, custom_fn=None, n_trials=None, n_worker
self.custom_fn = custom_fn
self.verbose = verbose
self.calibrated = False

# Handle if the sim has already been run
if self.sim.complete:
print('Warning: sim has already been run; re-initializing, but in future, use a sim that has not been run')
self.sim = self.sim.copy()
self.sim.initialize()

return


Expand Down Expand Up @@ -1316,7 +1323,7 @@ def run_trial(self, trial):
''' Define the objective for Optuna '''
pars = {}
for key, (best,low,high) in self.calib_pars.items():
pars[key] = trial.suggest_uniform(key, low, high) # Sample from beta values within this range
pars[key] = trial.suggest_uniform(key, low, high) # Sample from values within this range
mismatch = self.run_sim(pars)
return mismatch

Expand Down Expand Up @@ -1353,6 +1360,7 @@ def calibrate(self, calib_pars=None, verbose=True, **kwargs):
Args:
calib_pars (dict): if supplied, overwrite stored calib_pars
verbose (bool): whether to print output from each trial
kwargs (dict): if supplied, overwrite stored run_args (n_trials, n_workers, etc.)
'''

Expand All @@ -1368,8 +1376,8 @@ def calibrate(self, calib_pars=None, verbose=True, **kwargs):
t0 = sc.tic()
self.make_study()
self.run_workers()
study = op.load_study(storage=self.run_args.storage, study_name=self.run_args.name)
self.best_pars = sc.objdict(study.best_params)
self.study = op.load_study(storage=self.run_args.storage, study_name=self.run_args.name)
self.best_pars = sc.objdict(self.study.best_params)
self.elapsed = sc.toc(t0, output=True)

# Compare the results
Expand Down
3 changes: 1 addition & 2 deletions docs/tutorials/tut_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
" mismatch = np.mean(mismatches)\n",
" return mismatch\n",
"\n",
"guess = [0.01, 1] # Initial guess of parameters -- beta and relative death probability\n",
"guess = [0.015, 1] # Initial guess of parameters -- beta and relative death probability\n",
"pars = scipy.optimize.minimize(objective, x0=guess, method='nelder-mead') # Run the optimization\n",
"```"
]
Expand Down Expand Up @@ -216,7 +216,6 @@
"outputs": [],
"source": [
"# Plot the results\n",
"calib.summarize()\n",
"calib.plot(to_plot=['cum_tests', 'cum_diagnoses', 'cum_deaths'])"
]
},
Expand Down
3 changes: 1 addition & 2 deletions examples/t07_optuna_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@
n_workers = 4
calib = sim.calibrate(calib_pars=calib_pars, n_trials=n_trials, n_workers=n_workers)

# Summarize and plot the results
calib.summarize()
# Plot the results
calib.plot(to_plot=['cum_tests', 'cum_diagnoses', 'cum_deaths'])

0 comments on commit 56ab243

Please sign in to comment.