Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
keywords = ["markov chain monte carlo", "probabilistic programming"]
license = "MIT"
desc = "A lightweight interface for common MCMC methods."
version = "5.9.0"
version = "5.10.0"

[deps]
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
Expand Down
7 changes: 7 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ AbstractMCMC defines the abstract type `AbstractChains` for Markov chains.
AbstractMCMC.AbstractChains
```

The following two functions exist for converting `AbstractChains` from and to matrices of samples.

```@docs
AbstractMCMC.to_samples
AbstractMCMC.from_samples
```

For chains of this type, AbstractMCMC defines the following two methods.

```@docs
Expand Down
31 changes: 31 additions & 0 deletions src/AbstractMCMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ parameter samples generated through a MCMC process.
"""
abstract type AbstractChains end

"""
AbstractMCMC.from_samples(::Type{T}, samples::Matrix) where {T<:AbstractChains}

Convert a Matrix of parameter samples to an `AbstractChains` object.

Methods of this function should be implemented with the signature listed above, and should
return a chain of type `T`.

This function is the inverse of [`to_samples`](@ref).

In general, it is expected that for `chains::Tchn`, `from_samples(Tchn, to_samples(Tsample,
chains))` contains data that are equivalent to that in `chains` (although differences in
e.g. metadata or ordering are permissible).

Furthermore, the same should hold true for `to_samples(Tsample, from_samples(Tchn,
samples))` where `samples::Matrix{Tsample}`.
"""
function from_samples end

"""
AbstractMCMC.to_samples(::Type{T}, chains::AbstractChains) where {T}

Convert an `AbstractChains` object to an `Matrix` of parameter samples.

Methods of this function should be implemented with the signature listed above, and should
return a `Matrix{T}`.

See also: [`from_samples`](@ref).
"""
function to_samples end

"""
AbstractSampler

Expand Down
Loading