Sampling - NCSU

13
Sampling (Practical) Mihaela Paun University of Glasgow, UK

Transcript of Sampling - NCSU

Page 1: Sampling - NCSU

Sampling(Practical)MihaelaPaun

UniversityofGlasgow,UK

Page 2: Sampling - NCSU

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.

Page 3: Sampling - NCSU

Exercise3-- DRAM

• GotoSampling_Code_Exercise3 inthedownloadedfolder• YoushouldhaveMCMC_run folderinsidethisfolder• OpenBanana_DRAM_MainScript.m

• Spendroughly10minutestofamiliariseyourselveswiththiscode

Page 4: Sampling - NCSU

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)

Page 5: Sampling - NCSU

DRAM– ExamplesolutionsAdaptationinterval=5Adaptationinterval=1000

Page 6: Sampling - NCSU

DRAM– Examplesolutions

nSamples =1000nSamples =5000

Page 7: Sampling - NCSU

Errorvariance=1Errorvariance=10

DRAM– Examplesolutions

Page 8: Sampling - NCSU

Exercise3– HMC

• OpenBanana_HMC_MainScript.m• Spendroughly10minutestofamiliariseyourselveswiththiscode

Page 9: Sampling - NCSU

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)

Page 10: Sampling - NCSU

HMC– ExamplesolutionsNumberofsteps=10Numberofsteps=50

Page 11: Sampling - NCSU

HMC– Examplesolutions

Stepsize=0.003Stepsize=0.03

Page 12: Sampling - NCSU

Task– DRAMvsHMC

CompareDRAM&HMCintermsof:

- Inferenceaccuracy- Mixing(fromtraceplots)- ESS- ACF- acceptancerate

Page 13: Sampling - NCSU

DRAM HMC

ESS:(67,91)/5000,accRate:18%ESS:(4041,1978)/5000,accRate:98.9%