Path: blob/master/notebooks/book2/opt/simulated_annealing_2d_demo.ipynb
1192 views
Kernel: Python [conda env:py3713_2]
Simulated annealing on a 2d surface
Code is based on
and modified by murphyk@, Neoanarika@
In [1]:
Target distribution
We use the peaks function from matlab, modified so it is positive: $$ p(x,y) \propto |3 (1-x)^2 e^{-x^2 - (y+1)^2}
10 (\frac{x}{5} - x^3 - y^5) e^{-x^2 -y^2}
\frac{1}{3} e^{-(x+1)^2 - y^2} | $$
In [2]:
In [3]:
Out[3]:
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
In [4]:
In [5]:
Out[5]:
/home/patel_zeel/miniconda3/envs/py3713_2/lib/python3.7/site-packages/ipykernel_launcher.py:3: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
This is separate from the ipykernel package so we can avoid doing imports until
/home/patel_zeel/Probml_karm/probml-utils/probml_utils/plotting.py:80: UserWarning: set FIG_DIR environment variable to save figures
warnings.warn("set FIG_DIR environment variable to save figures")
In [6]:
Out[6]:
/home/patel_zeel/miniconda3/envs/py3713_2/lib/python3.7/site-packages/ipykernel_launcher.py:3: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
This is separate from the ipykernel package so we can avoid doing imports until
Heat bath
The "heat bath" refers to a modified version of the distribution in which we vary the temperature.
In [7]:
Out[7]:
/home/patel_zeel/miniconda3/envs/py3713_2/lib/python3.7/site-packages/ipykernel_launcher.py:3: MatplotlibDeprecationWarning: Calling gca() with keyword arguments was deprecated in Matplotlib 3.4. Starting two minor releases later, gca() will take no keyword arguments. The gca() function should only be used to get the current axes, or if no axes exist, create new axes with default keyword arguments. To create a new axes with non-default arguments, use plt.axes() or plt.subplot().
This is separate from the ipykernel package so we can avoid doing imports until
SA algorithm
In [8]:
Run experiments
In [9]:
Out[9]:
/home/patel_zeel/Probml_karm/probml-utils/probml_utils/plotting.py:26: UserWarning: LATEXIFY environment variable not set, not latexifying
warnings.warn("LATEXIFY environment variable not set, not latexifying")
In [10]:
Out[10]:
gaussian
jnproposed 301, naccepted 92, nreject 208
uniform
jnproposed 301, naccepted 33, nreject 267
In [11]:
Out[11]:
In [12]:
Out[12]: