Skip to content

Commit

Permalink
New Gibbs sampler using condition (#2099)
Browse files Browse the repository at this point in the history
* initial work on the new gibbs sampler

* added tests for the new Gibbs sampler

* added tests for new Gibbs

* new Gibbs is now sampling (correctly) sequentially

* let's not overload merge just yet

* export GibbsV2 + added more samplers to the tests

* added TODO comment

* removed lots of varinfo related merging functionality that is now
available in DynamicPPL

* shifting some code around

* removed redundant constructor for GibbsV2

* added GibbsContext which is similar to FixContext but also computes
the log-prob of the fixed variables

* adopted the rerun mechanism in Gibbs for GibbsV2, thus fixing the
issues with some of the tests for GibbsV2

* broken tests are no longer broken

* fix issues with dot_tilde_* impls for GibbsContext

* fix for dot_tilde_assume when using GibbsContext

* fixed re-running of models for Gibbs sampling properly this time

* added new gibbs to tests

* added some further comments on why we need `GibbsContext`

* went back to using `DynamicPPL.condition` rather than using custom
`GibbsContext` while we wait for
TuringLang/DynamicPPL.jl#563 to be merged

* add concrete comment about reverting changes for `gibbs_condition`

* Update test/mcmc/gibbs_new.jl

Co-authored-by: Hong Ge <[email protected]>

* fixed recursive definition of `condition` varinfos

* use `fix` instead of `condition`

* Revert "use `fix` instead of `condition`"

This reverts commit f87e2d1.

* rmeoved unnused symbol

* Revert "went back to using `DynamicPPL.condition` rather than using custom"

This reverts commit 53bd707.

* bump compat entry of DynamicPPL so we can overload acclogp!

* update assume for SMC samplers to make use of new `acclogp!`

* added proper impl of acclogp!! for SMC samplers + made accessing
task local varinfo and rng a bit nicer

* added experimental module and moved gibbs to it

* fixed now-inccorect references in new gibbs file

* updated gibbs tests

* moved experimental gibbs tests

* updated tests to include experiemntal tests

* removed refrences to previews tests of experimental Gibbs sampler

* removed solved TODO

* added a comment on `reconstruct_getvalue` usage

* bump patch version

* added comments on future work

* Update test/experimental/gibbs.jl

* fixed bug where particle samplers didn't properly account for
weightings of logpdf, etc.

* relax atol for a numerical test with Gibbs a bit

* fixed bug with `AbstractDict` constructor for experimental `Gibbs`

* aaaalways link the varinfo in the new Gibbs sampler, just to be sure

* add test to cover recent improvement to `DynamicPPL.subset`

ref: TuringLang/DynamicPPL.jl#587

* bump compat entry for DynamicPPL

* added some docstrings

* fixed test

* fixed import

* another attempt at fixing tests

* another attempt at fixing tests

* attempt at fix tests

* forgot something in previos commit

* cleaned up the experimental Gibbs sampler a bit

* removed accidentaly psuedocode inclusion

* Apply suggestions from code review

* relaxed olerance in one MH test a bit

* bump patch version

---------

Co-authored-by: Hong Ge <[email protected]>
  • Loading branch information
torfjelde and yebai authored Apr 21, 2024
1 parent fa6f30a commit a022dc6
Show file tree
Hide file tree
Showing 10 changed files with 774 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.30.8"
version = "0.30.9"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -58,7 +58,7 @@ Distributions = "0.23.3, 0.24, 0.25"
DistributionsAD = "0.6"
DocStringExtensions = "0.8, 0.9"
DynamicHMC = "3.4"
DynamicPPL = "0.24.7"
DynamicPPL = "0.24.10"
EllipticalSliceSampling = "0.5, 1, 2"
ForwardDiff = "0.10.3"
Libtask = "0.7, 0.8"
Expand Down
1 change: 1 addition & 0 deletions src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ using .Variational
include("optimisation/Optimisation.jl")
using .Optimisation

include("experimental/Experimental.jl")
include("deprecated.jl") # to be removed in the next minor version release

###########
Expand Down
16 changes: 16 additions & 0 deletions src/experimental/Experimental.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Experimental

using Random: Random
using AbstractMCMC: AbstractMCMC
using DynamicPPL: DynamicPPL, VarName
using Setfield: Setfield

using DocStringExtensions: TYPEDFIELDS
using Distributions

using ..Turing: Turing
using ..Turing.Inference: gibbs_rerun, InferenceAlgorithm

include("gibbs.jl")

end
Loading

2 comments on commit a022dc6

@torfjelde
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

New features

  • Turing.Experimental module where more experimental features will go, with the aim of eventually making its way into Turing proper.
  • Turing.Experimental.Gibbs is a new implementation of the Gibbs sampler which provides much greater flexibility specifying which variables should use which sampler. Note that this is in the Turing.Experimental module, and thus will be prone to changes.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105315

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.30.9 -m "<description of version>" a022dc6b5990199187018e64501b3da0d7d0bb29
git push origin v0.30.9

Please sign in to comment.