Speed up the notebook to ~25sec
reducing the number of walkers and Nrun to execute it in about 25sec instead of 100s
"dataset.parameters[\"lambda_\"].frozen = False\n",
"\n",
"\n",
- "dataset.background_model.parameters[\"norm\"].frozen = False\n",
+ "dataset.background_model.parameters[\"norm\"].frozen = True\n",
"dataset.background_model.parameters[\"tilt\"].frozen = True\n",
"\n",
"dataset.background_model.parameters[\"norm\"].min = 0.5\n",
"# Setting amplitude init values a bit offset to see evolution\n",
"# Here starting close to the real value\n",
"dataset.parameters[\"index\"].value = 2.0\n",
- "dataset.parameters[\"amplitude\"].value = 3.3e-12\n",
+ "dataset.parameters[\"amplitude\"].value = 3.2e-12\n",
"dataset.parameters[\"lambda_\"].value = 0.05\n",
"\n",
"print(dataset.model)\n",
},
"outputs": [],
"source": [
+ "\n",
"# Now let's define a function to init parameters and run the MCMC with emcee\n",
"# Depending on your number of walkers, Nrun and dimensionality, this can take a while (> minutes)\n",
"\n",
"\n",
- "def run_mcmc(dataset, nwalkers=12, nrun=500, threads=1):\n",
+ "def run_mcmc(dataset, nwalkers=8, nrun=1000, threads=1):\n",
" \"\"\"\n",
" Run the MCMC sampler.\n",
" \n",
" return sampler\n",
"\n",
"\n",
- "sampler = run_mcmc(dataset, nwalkers=8, nrun=500) # to speedup the notebook\n",
- "# sampler=run_mcmc(dataset,nwalkers=16,nrun=1000) # more accurate contours"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Plotting the results"
+ "sampler = run_mcmc(dataset, nwalkers=6, nrun=150) # to speedup the notebook\n",
+ "# sampler=run_mcmc(dataset,nwalkers=12,nrun=1000) # more accurate contours"
]
},
{
" )\n",
"\n",
"\n",
- "plot_corner(sampler, dataset, nburn=200)"
+ "plot_corner(sampler, dataset, nburn=50)"
]
},
{
"outputs": [],
"source": [
"emin, emax = [0.1, 100] * u.TeV\n",
- "nburn = 300\n",
+ "nburn = 50\n",
"\n",
"fig, ax = plt.subplots(1, 1, figsize=(12, 6))\n",
"\n",
- "for nwalk in range(0, 8):\n",
+ "for nwalk in range(0, 6):\n",
" for n in range(nburn, nburn + 100):\n",
" pars = sampler.chain[nwalk, n, :]\n",
"\n",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.0"
+ "version": "3.6.7"
}
},
"nbformat": 4,
