Path: blob/master/deprecated/notebooks/simulated_annealing_2d_demo.ipynb
1192 views
Kernel: Python 3
Simulated annealing on a 2d surface
Code is based on
and modified by murphyk@ and Neoanarika@
In [1]:
In [2]:
Out[2]:
/content/scripts
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 [3]:
In [4]:
Out[4]:
saving image to ../figures/sim_anneal_2d_peaks.pdf
In [5]:
Out[5]:
saving image to ../figures/sim_anneal_2d_energy.pdf
Heat bath
The "heat bath" refers to a modified version of the distribution in which we vary the temperature.
In [6]:
Out[6]:
saving image to ../figures/sim_anneal_2d_cooled0.pdf
saving image to ../figures/sim_anneal_2d_cooled1.pdf
saving image to ../figures/sim_anneal_2d_cooled2.pdf
saving image to ../figures/sim_anneal_2d_cooled3.pdf
SA algorithm
In [54]:
Run experiments
In [55]:
Out[55]:
uniform
nproposed 301, naccepted 33, nreject 267
gaussian
nproposed 301, naccepted 104, nreject 196
In [56]:
Out[56]:
saving image to ../figures/sim_anneal_2d_temp_vs_time_uniform.pdf
saving image to ../figures/sim_anneal_2d_temp_vs_time_gaussian.pdf
In [57]:
Out[57]:
saving image to ../figures/sim_anneal_2d_prob_vs_time_uniform.pdf
saving image to ../figures/sim_anneal_2d_prob_vs_time_gaussian.pdf
In [58]:
Out[58]:
saving image to ../figures/sim_anneal_2d_samples_uniform.pdf
saving image to ../figures/sim_anneal_2d_samples_gaussian.pdf
In [ ]: