Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MH Constructor #2037

Merged
merged 33 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
94bc38e
first draft
JaimeRZP Jul 6, 2023
26f5bac
abstractcontext + tests
JaimeRZP Jul 6, 2023
b31908f
bug
JaimeRZP Jul 6, 2023
af50188
externalsampler() in tests
JaimeRZP Jul 7, 2023
6725e4a
Name Tupple problems
JaimeRZP Jul 7, 2023
427bef4
moving stuff to DynamicPPL RP
JaimeRZP Jul 11, 2023
c022765
using new DynamicPPL PR
JaimeRZP Jul 14, 2023
9ea3550
mistakenly removed line
JaimeRZP Jul 14, 2023
bdf5110
specific constructors
JaimeRZP Jul 14, 2023
6025d70
Merge branch 'master' into MH_constructor
JaimeRZP Jul 17, 2023
4ab5939
no StaticMH RWMH
JaimeRZP Jul 17, 2023
74869f4
Bump bijectors compat (#2052)
yebai Jul 27, 2023
2e76333
Merge branch 'master' into MH_constructor
yebai Jul 27, 2023
17960f4
Merge branch 'master' into MH_constructor
yebai Jul 29, 2023
0176407
Bugfixes.
yebai Jul 30, 2023
f775f52
Add TODO.
yebai Jul 30, 2023
fb5612f
Update mh.jl
yebai Jul 30, 2023
0abebd7
Update Inference.jl
yebai Jul 30, 2023
3dae981
Removed obsolete exports.
yebai Jul 30, 2023
f792d73
removed unnecessary import of extract_priors
torfjelde Jul 31, 2023
b19abdc
added missing ) in MH tests
torfjelde Jul 31, 2023
7f42b53
fixed incorrect referneces to AdvancedMH in tests
torfjelde Jul 31, 2023
dfc5285
Merge branch 'master' into MH_constructor
torfjelde Jul 31, 2023
411d030
improve ESLogDensityFunction
torfjelde Jul 31, 2023
7dd122a
remove hardcoding of SimpleVarInfo
torfjelde Jul 31, 2023
5f0963e
added fixme comment
torfjelde Jul 31, 2023
70ddc23
minor style changes
torfjelde Jul 31, 2023
3fcb839
fixed issues with MH with RandomWalkProposal being used as an externa…
torfjelde Jul 31, 2023
47584f8
fixed accidental typo
torfjelde Jul 31, 2023
bdc87b9
move definitions of unflatten for NamedTuple
torfjelde Jul 31, 2023
ef27088
improved TODO
torfjelde Jul 31, 2023
045e2d0
Update Project.toml
yebai Aug 16, 2023
286a974
Merge branch 'master' into MH_constructor
yebai Aug 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export @model, # modelling

MH, # classic sampling
RWMH,
StaticMH,
Emcee,
ESS,
Gibbs,
Expand Down
3 changes: 3 additions & 0 deletions src/inference/Inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import AdvancedMH; const AMH = AdvancedMH
import AdvancedPS
import BangBang
import ..Essential: getADbackend
import DynamicPPL: extract_priors
import EllipticalSliceSampling
import LogDensityProblems
import LogDensityProblemsAD
Expand All @@ -45,6 +46,8 @@ export InferenceAlgorithm,
SampleFromUniform,
SampleFromPrior,
MH,
RWMH,
StaticMH,
ESS,
Emcee,
Gibbs, # classic sampling
Expand Down
16 changes: 16 additions & 0 deletions src/inference/mh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ function MH(space...)
return MH{tuple(syms...), typeof(proposals)}(proposals)
end

function StaticMH(model::Model)
return MH(model; proposal_type=AMH.StaticProposal)
end

function RWMH(model::Model)
return MH(model; proposal_type=AMH.RandomWalkProposal)
end

function MH(model::Model; proposal_type=AMH.StaticProposal)
priors = extract_priors(model)
props = Tuple([proposal_type(prop) for prop in values(priors)])
vars = Symbol.(keys(priors))
priors = NamedTuple{Tuple(vars)}(props)
return AMH.MetropolisHastings(priors)
end

#####################
# Utility functions #
#####################
Expand Down
6 changes: 6 additions & 0 deletions test/inference/mh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

s4 = Gibbs(MH(:m), MH(:s))
c4 = sample(gdemo_default, s4, N)

s5 = externalsampler(RWMH(gdemo_default))
c5 = sample(gdemo_default, s5, N)

s6 = externalsampler(StaticMH(gdemo_default))
c6 = sample(gdemo_default, s6, N)
end
@numerical_testset "mh inference" begin
Random.seed!(125)
Expand Down