Sampling - NCSU
Transcript of Sampling - NCSU
Sampling(Practical)MihaelaPaun
UniversityofGlasgow,UK
ObjectiveCriticallyassesstheperformanceoftwosamplingalgorithms:
DelayedRejectionAdaptiveMetropolis(DRAM)andHamiltonianMonteCarlo(HMC)onatoyproblem:thebanana-shapeddistribution.
• Thebanana-shapedposteriordistributioncanbegeneratedusingthefollowinglikelihoodandprior:
yi|ϴ~N(ϴ1+ϴ22,σy2)
ϴi ~N(0,σϴ2),i=1,2Thedata{yi,i=1,…100}aregeneratedwithϴ1+ϴ2
2 =1,σy =2,σϴ=1.
Exercise3-- DRAM
• GotoSampling_Code_Exercise3 inthedownloadedfolder• YoushouldhaveMCMC_run folderinsidethisfolder• OpenBanana_DRAM_MainScript.m
• Spendroughly10minutestofamiliariseyourselveswiththiscode
Tasks(DRAM)WewillimplementDRAMonthebanana-shapeddistribution.
Inthe‘Generatedata’ section,wesettheerrorvariance(line7).Inthe‘RunDRAM’ section,wedefinethenumberofsamples(line24),theadaptationinterval(line28),andtheproposalcovariance(line31).
Pleaserecord howthefollowingdifferasyouchangetheabovequantities:- Inferenceaccuracy(line67)- Traceplots (lines37-39)- ESS(lines57-58)- ACF(lines60-62)- acceptancerate(line64)
DRAM– ExamplesolutionsAdaptationinterval=5Adaptationinterval=1000
DRAM– Examplesolutions
nSamples =1000nSamples =5000
Errorvariance=1Errorvariance=10
DRAM– Examplesolutions
Exercise3– HMC
• OpenBanana_HMC_MainScript.m• Spendroughly10minutestofamiliariseyourselveswiththiscode
Tasks(HMC)WewillgeneratessamplesfromtheposteriordistributionusingtheHMCalgorithm.
Inthe‘RunHMC’ section,wedefinethenumberofHMCsamples(line19),thenumberofleapfrogsteps(line20)andthestepsize(line21)fortheleapfrogscheme.
Pleaserecord howthefollowingdifferasyouchangetheabovequantities:- Inferenceaccuracy(line80)- Traceplots (lines57-59)- ESS(lines70-71)- ACF(lines73-75)- acceptancerate(line77)
HMC– ExamplesolutionsNumberofsteps=10Numberofsteps=50
HMC– Examplesolutions
Stepsize=0.003Stepsize=0.03
Task– DRAMvsHMC
CompareDRAM&HMCintermsof:
- Inferenceaccuracy- Mixing(fromtraceplots)- ESS- ACF- acceptancerate
DRAM HMC
ESS:(67,91)/5000,accRate:18%ESS:(4041,1978)/5000,accRate:98.9%