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−x4, 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−x4dx=41Γ(4k+1) to show that ⟨x2⟩=Γ(3/4)/Γ(1/4)=0.3380 and ⟨x4⟩=41, and find var(x2). (b) Write the sampler. Start at x=0 and take N=2×105 steps with NumPy's default generator (PCG64), seed 2: draw xi = rng.standard_normal(N) and then u = rng.random(N). At step i propose y=x+sξi, accept if ui<exp[−(y4−x4)], and record x2 after the step, the old value again if the move is rejected. Run it with s=0.1, 1.4 and 8.0. (c) For each run report the acceptance, the average of x2, its blocked error from 100 blocks of 2000 steps, τint of x2 from that error and the var(x2) of part (a), and Neff. (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.4 again with seeds 3 and 4 and compare the scatter of the three averages with the blocked error.