Skip to content

Commit

Permalink
Few more changes to tidy up notebook 06
Browse files Browse the repository at this point in the history
  • Loading branch information
jtrauer committed Feb 8, 2024
1 parent da7f87b commit d6ecd96
Showing 1 changed file with 8 additions and 35 deletions.
43 changes: 8 additions & 35 deletions renew/06-calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"priors.append(esp.UniformPrior(proc_req['name'], (proc_req['lower'], proc_req['upper']), size=n_process_periods))\n",
"renewal_model = RenewalModel(calib_kwargs['pop'], n_times, run_in, n_process_periods)\n",
"obj_func = get_obj_func(renewal_model)\n",
"n_draws = 100\n",
"n_draws = 100 # This is obviously far too short - demonstration code only\n",
"\n",
"with pm.Model() as pmm:\n",
" variables = use_model(priors, obj_func)\n",
Expand All @@ -103,33 +103,16 @@
"az.summary(idata)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e294388",
"metadata": {},
"outputs": [],
"source": [
"mean_posterior_params = mpp = np.array(az.summary(idata)[\"mean\"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "85898c36",
"metadata": {},
"outputs": [],
"source": [
"incidence = renewal_model.func(mpp[0], mpp[1], mpp[4:], np.log(mpp[3])).incidence * mpp[2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f77ea75-5a92-45ec-bafc-2e417d7457c2",
"metadata": {},
"outputs": [],
"source": [
"# Pull out a parameter set to look at a single run\n",
"mpp = np.array(az.summary(idata)[\"mean\"])\n",
"incidence = renewal_model.func(mpp[0], mpp[1], mpp[4:], np.log(mpp[3])).incidence * mpp[2]\n",
"inc = pd.DataFrame(incidence)\n",
"inc[\"targets\"] = mys_data\n",
"inc.plot()"
Expand Down Expand Up @@ -159,9 +142,10 @@
"spaghetti = pd.DataFrame()\n",
"for i, p in enumerate(sample_params):\n",
" incidence = renewal_model.func(p['gen_mean'], p['gen_sd'], p['random_process'], np.log(p['seed'])).incidence\n",
" cdr = p['cdr']\n",
" spaghetti[i] = incidence * cdr\n",
"spaghetti.columns = sample_params.index.to_flat_index().map(str)"
" spaghetti[i] = incidence * p['cdr']\n",
"spaghetti.columns = sample_params.index.to_flat_index().map(str)\n",
"spaghetti['targets'] = calib_kwargs['targets']\n",
"spaghetti.plot()"
]
},
{
Expand All @@ -177,17 +161,6 @@
"params_table = params_table.rename_axis(None)\n",
"params_table = params_table.rename(columns={'init': 'Starting value', 'lower': 'Lower limit', 'upper': 'Upper limit'})"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "70ab40ed-8da4-4464-bb7b-64058bf063f1",
"metadata": {},
"outputs": [],
"source": [
"spaghetti['targets'] = calib_kwargs['targets']\n",
"spaghetti.plot()"
]
}
],
"metadata": {
Expand Down

0 comments on commit d6ecd96

Please sign in to comment.