Sample the density

PHYSICS · Subjective · Fermi University Physics · Mathematical Methods for Physics · Computational Physics · Monte Carlo and lattice simulation of physical systems

Error, Chance and the Machine, Ch Markov-chain Monte Carlo

Problem

Sample the density p(x)∝e−x4p(x) \propto e^{-x^4}, a stiffer well than the Gaussian of Section 11.3, with a random-walk Metropolis chain, and measure the cost of three proposal widths. (a) Use ∫0∞xke−x4 dx=14Γ ⁣(k+14)\int_0^\infty x^k e^{-x^4}\,\mathrm{d}x = \tfrac14\Gamma\!\left(\tfrac{k+1}{4}\right) to show that ⟨x2⟩=Γ(3/4)/Γ(1/4)=0.3380\langle x^2\rangle = \Gamma(3/4)/\Gamma(1/4) = 0.3380 and ⟨x4⟩=14\langle x^4\rangle = \tfrac14, and find var(x2)\mathrm{var}(x^2). (b) Write the sampler. Start at x=0x = 0 and take N=2×105N = 2\times10^5 steps with NumPy's default generator (PCG64), seed 22: draw xi = rng.standard_normal(N) and then u = rng.random(N). At step ii propose y=x+s ξiy = x + s\,\xi_i, accept if ui<exp⁡[−(y4−x4)]u_i < \exp[-(y^4 - x^4)], and record x2x^2 after the step, the old value again if the move is rejected. Run it with s=0.1s = 0.1, 1.41.4 and 8.08.0. (c) For each run report the acceptance, the average of x2x^2, its blocked error from 100100 blocks of 20002000 steps, τint\tau_{\rm int} of x2x^2 from that error and the var(x2)\mathrm{var}(x^2) of part (a), and NeffN_{\rm eff}. (d) Which width is best? Compare with the rule of Section 11.3, using the standard deviation of the target. Give the difference of each average from the exact value in blocked errors. Then run s=1.4s = 1.4 again with seeds 33 and 44 and compare the scatter of the three averages with the blocked error.

Browse the problem library