hopsy.sample#
- class hopsy.sample(markov_chains, rngs, n_samples, thinning=1, n_procs=1)#
Draw
n_samples
from every passed chain inmarkov_chains
using the respective random number generator fromrngs
. Thus,len(rngs)
has to matchlen(markov_chains)
.- Parameters:
markov_chains (list[hopsy.MarkovChain] or hopsy.MarkovChain) – (List of) Markov chain(s) to simulate to generate samples.
rngs (list[hopsy.RandomNumberGenerator] or hopsy.RandomNumberGenerator) – (List of) random number generator(s) to simulate the Markov chains. If a single
hopsy.MarkovChain
was passed tosample
, thenrng
also must be a singlehopsy.RandomNumberGenerator
.n_samples (int) – Number of samples to draw from every chain.
thinning (int) – Number of samples to discard inbetween two saved states. This will increase the number of samples actually produced by the chain to
thinning * n_samples
.n_threads (int) – (deprecated) Number of parallel processes to use. Parallelization is achieved using
multiprocessing
. The worker pool size will bemin(n_procs, len(markov_chains))
n_procs (int) – Number of parallel processes to use. Parallelization is achieved using
multiprocessing
. The worker pool size will bemin(n_procs, len(markov_chains))
record_meta (list[str] or bool) – Strings defining
hopsy.MarkovChain
attributes oracceptance_rate
, which will then be recorded and returned. All attributes ofhopsy.MarkovChain
can be used here, e.g.record_meta=['state_negative_log_likelihood', 'proposal.proposal']
.in_memory (bool) – Flag for enabling or disabling in-memory saving of states and metadata.
callback (derived from hopsy.Callback) – Observer callback to which states and metadata are passed during the run. The callback is e.g. used to write the obtained information online to permanent storage. This enables online analysis of the MCMC run.
- Returns:
First value of the tuple holds meta information about the states. Without using
record_meta
, this is a list containing the acceptance rates of each chain. Ifrecord_meta
is used, then this is a dict containing the values of thehopsy.MarkovChain
attributes defined inrecord_meta
. If the attribute was not found (e.g. because of a typo), it will have valueNone
.Second value of the tuple holds produced states. Will have shape
(n_chains, n_draws, dim)
. For single chains, it will thus be(1, n_draws, dim)
.If
in_memory=False
,None
will be returned.- Return type:
optional[tuple[list or dict, numpy.ndarray]]