slicesample
Slice sampler
Syntax
rnd = slicesample(initial,nsamples,'pdf',pdf)
rnd = slicesample(initial,nsamples,'logpdf',logpdf)
[rnd,neval]
= slicesample(initial,...)
[rnd,neval]
= slicesample(initial,...,Name,Value)
Description
generates rnd
= slicesample(initial
,nsamples
,'pdf',pdf
)nsamples
random samples using the slice sampling method (see Algorithms). pdf
gives the target probability density function (pdf). initial
is a row vector or scalar containing the initial value of the random sample sequences.
generates samples using the logarithm of the pdf.rnd
= slicesample(initial
,nsamples
,'logpdf',logpdf
)
[
returns the average number of function evaluations that occurred in the slice sampling.rnd
,neval
]
= slicesample(initial
,...)
[
generates random samples with additional options specified by one or more rnd
,neval
]
= slicesample(initial
,...,Name,Value
)Name,Value
pair arguments.
Input Arguments
|
Initial point, a scalar or row vector. Set |
|
Positive integer, the number of samples that |
|
Handle to a function that generates the probability density function, specified with |
|
Handle to a function that generates the logarithm of the probability density function, specified with |
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
|
Nonnegative integer, the number of samples to generate and discard before generating the samples to return. The slice sampling algorithm is a Markov chain whose stationary distribution is proportional to that of the Default: |
|
Positive integer, where Default: |
|
Width of the interval around the current sample, a scalar or vector of positive values.
Default: |
Output Arguments
|
|
|
Scalar, the mean number of function evaluations per sample.
|
Examples
Tips
There are no definitive suggestions for choosing appropriate values for
burnin
,thin
, orwidth
. Choose starting values ofburnin
andthin
, and increase them, if necessary, to give the requisite independence and marginal distributions. See Neal [1] for details of the effect of adjustingwidth
.
Algorithms
At each point in the sequence of random samples, slicesample
selects the next point by “slicing” the density to form a neighborhood around the previous point where the density is above some value. Consequently, the sample points are not independent. Nearby points in the sequence tend to be closer together than they would be from a sample of independent values. For many purposes, the entire set of points can be used as a sample from the target distribution. However, when this type of serial correlation is a problem, the burnin
and thin
parameters can help reduce that correlation.
slicesample
uses the slice sampling algorithm of Neal [1]. For numerical stability, it converts a pdf
function into a logpdf
function. The algorithm to resize the support region for each level, called “stepping-out” and “stepping-in,” was suggested by Neal.
References
[1] Neal, Radford M. "Slice Sampling." Ann. Stat. Vol. 31, No. 3, pp. 705–767, 2003. Available at Project Euclid.
Version History
Introduced in R2006a