.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/plot_eggbox.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_plot_eggbox.py: ====== Eggbox ====== A likelihood surface with multiple modes of equal height. .. GENERATED FROM PYTHON SOURCE LINES 8-36 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt import corner import nestle # Define the posterior density to be sampled: tmax = 5.0 * np.pi constant = np.log(1.0 / tmax**2) def loglike(x): t = 2.0 * tmax * x - tmax return (2.0 + np.cos(t[0]/2.0)*np.cos(t[1]/2.0))**5.0 def prior(x): return x # plot the surface plt.figure(figsize=(8., 8.)) ax = plt.axes(aspect=1) xx, yy = np.meshgrid(np.linspace(0., 1., 50), np.linspace(0., 1., 50)) Z = loglike(np.array([xx, yy])) ax.contourf(xx, yy, Z, 12, cmap=plt.cm.Blues_r) plt.title("True Log likelihood surface") .. image-sg:: /examples/images/sphx_glr_plot_eggbox_001.png :alt: True Log likelihood surface :srcset: /examples/images/sphx_glr_plot_eggbox_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'True Log likelihood surface') .. GENERATED FROM PYTHON SOURCE LINES 37-38 Run nested sampling in multi-ellipsoid mode and print a summary of results: .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python res = nestle.sample(loglike, prior, 2, npoints=200, method='multi', update_interval=20) print(res.summary()) .. rst-class:: sphx-glr-script-out .. code-block:: none niter: 1532 ncall: 3095 nsamples: 1732 logz: 236.196 +/- 0.170 h: 5.806 .. GENERATED FROM PYTHON SOURCE LINES 44-46 Plot the samples. Note that this represents the *likelihood* rather than its log, hence it is much more highly peaked. .. GENERATED FROM PYTHON SOURCE LINES 46-51 .. code-block:: Python fig = corner.corner(res.samples, weights=res.weights, bins=500, range=[(0., 1.), (0., 1.)]) fig.set_size_inches(8., 8.) .. image-sg:: /examples/images/sphx_glr_plot_eggbox_002.png :alt: plot eggbox :srcset: /examples/images/sphx_glr_plot_eggbox_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.700 seconds) .. _sphx_glr_download_examples_plot_eggbox.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_eggbox.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_eggbox.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_eggbox.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_