Skip to content

Commit 390012e

Browse files
authored
Add to_samples and from_samples (#184)
1 parent e58f735 commit 390012e

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
33
keywords = ["markov chain monte carlo", "probabilistic programming"]
44
license = "MIT"
55
desc = "A lightweight interface for common MCMC methods."
6-
version = "5.9.0"
6+
version = "5.10.0"
77

88
[deps]
99
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"

docs/src/api.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ AbstractMCMC defines the abstract type `AbstractChains` for Markov chains.
144144
AbstractMCMC.AbstractChains
145145
```
146146

147+
The following two functions exist for converting `AbstractChains` from and to matrices of samples.
148+
149+
```@docs
150+
AbstractMCMC.to_samples
151+
AbstractMCMC.from_samples
152+
```
153+
147154
For chains of this type, AbstractMCMC defines the following two methods.
148155

149156
```@docs

src/AbstractMCMC.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@ parameter samples generated through a MCMC process.
3030
"""
3131
abstract type AbstractChains end
3232

33+
"""
34+
AbstractMCMC.from_samples(::Type{T}, samples::Matrix) where {T<:AbstractChains}
35+
36+
Convert a Matrix of parameter samples to an `AbstractChains` object.
37+
38+
Methods of this function should be implemented with the signature listed above, and should
39+
return a chain of type `T`.
40+
41+
This function is the inverse of [`to_samples`](@ref).
42+
43+
In general, it is expected that for `chains::Tchn`, `from_samples(Tchn, to_samples(Tsample,
44+
chains))` contains data that are equivalent to that in `chains` (although differences in
45+
e.g. metadata or ordering are permissible).
46+
47+
Furthermore, the same should hold true for `to_samples(Tsample, from_samples(Tchn,
48+
samples))` where `samples::Matrix{Tsample}`.
49+
"""
50+
function from_samples end
51+
52+
"""
53+
AbstractMCMC.to_samples(::Type{T}, chains::AbstractChains) where {T}
54+
55+
Convert an `AbstractChains` object to an `Matrix` of parameter samples.
56+
57+
Methods of this function should be implemented with the signature listed above, and should
58+
return a `Matrix{T}`.
59+
60+
See also: [`from_samples`](@ref).
61+
"""
62+
function to_samples end
63+
3364
"""
3465
AbstractSampler
3566

0 commit comments

Comments
 (0)