matlab mhsample,slicesample,mhsample编程求助……

help slicesample

slicesample Slice sampling method.

RND = slicesample(INITIAL,NSAMPLES,'pdf',PDF) draws NSAMPLES random

samples from a target distribution with the density function PDF using

the slice sampling. INITIAL is a row vector or scalar containing the

initial value of the random sample sequences. INITIAL must be within

the domain of the target distribution. NSAMPLES is the number of

samples to be generated. PDF is a function handle created using @. PDF

takes only one argument as an input and this argument has the same type

and size as INITIAL. It defines a function that is proportional to the

target density function. If log density function is preferred, 'pdf'

can be replaced with 'logpdf'. The log density function is not

necessarily normalized, either.

RND = slicesample(...,'width',W) performs slice sampling for the target

distribution with a typical width W. W is a scalar or vector. If it is

a scalar, all dimensions are assumed to have the same typical widths.

If it is a vector, each element of the vector is the typical width of

the marginal target distribution in that dimension. The default value

of W is 10.

RND = slicesample(...,'burnin',K) generates random samples with values

between the starting point and the K-th point omitted in the generated

sequence, but keep points after that. K is a non-negative integer. The

default value of K is 0.

RND = slicesample(...,'thin',M) generates random samples with M-1 out of

M values omitted in the generated sequence. M is a positive integer.

The default value of M is 1.

[RND, NEVAL] = slicesample(...) also returns NEVAL as the averaged

number of function evaluations occurred in the slice sampling. NEVAL is

a scalar.

Example:

Generate random samples from a distribution with a user-defined pdf:

f = @(x) exp( -x.^2/2).* ...       % This is a function proportional

(1+(sin(3*x)).^2).* ...   % to the pdf for a multi-modal

(1+(cos(5*x).^2));        % distribution

x = slicesample(1,2000,'pdf',f,'thin',5,'burnin',1000);

hist(x,50)

set(get(gca,'child'),'facecolor',[0.6 .6 .6]);

hold on

xd = get(gca,'XLim');              % Gets the x-data of the bins.

binwidth = (xd(2)-xd(1));          % Finds the width of each bin.

y = 5.6398*binwidth* ...           % Normalization necessary to

f(linspace(xd(1),xd(2),1000)); % overplot the histogram.

plot(linspace(xd(1),xd(2),1000),y,'r')

See also: mhsample, rand, hist, plot.

Reference page in Help browser

doc slicesample

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值