-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extension for MCMCChains (#514)
* added extension for MCMCChains * bump patch versoin * added entry to .gitignore * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * forgot to add MCMCChains to extras * Update ext/DynamicPPLMCMCChainsExt.jl Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1ebe8bc
commit 4a986df
Showing
5 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
*.jl.mem | ||
.DS_Store | ||
Manifest.toml | ||
**.~undo-tree~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module DynamicPPLMCMCChainsExt | ||
|
||
using DynamicPPL: DynamicPPL | ||
using MCMCChains: MCMCChains | ||
|
||
function DynamicPPL.generated_quantities(model::DynamicPPL.Model, chain::MCMCChains.Chains) | ||
chain_parameters = MCMCChains.get_sections(chain, :parameters) | ||
varinfo = DynamicPPL.VarInfo(model) | ||
iters = Iterators.product(1:size(chain, 1), 1:size(chain, 3)) | ||
return map(iters) do (sample_idx, chain_idx) | ||
DynamicPPL.setval_and_resample!(varinfo, chain_parameters, sample_idx, chain_idx) | ||
model(varinfo) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@testset "DynamicPPLMCMCChainsExt" begin | ||
@model demo() = x ~ Normal() | ||
model = demo() | ||
|
||
chain = MCMCChains.Chains(randn(1000, 2, 1), [:x, :y], Dict(:internals => [:y])) | ||
chain_generated = @test_nowarn generated_quantities(model, chain) | ||
@test size(chain_generated) == (1000, 1) | ||
@test mean(chain_generated) ≈ 0 atol = 0.1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4a986df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
4a986df
There was a problem hiding this comment.
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/89252
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: