Simple Rejection Sampling

版本 1.0.0.0 (1.7 KB) 作者: Dmitry Savransky
Return values sampled from a user defined distribution. Samples are not guaranteed IID.
1.4K 次下载
更新时间 2010/5/12

查看许可证

SAMPLEDIST Sample from an arbitrary distribution
sampleDist(f,M,N,b) retruns an array of size X of random values sampled from the distribution defined by the probability density function referred to by handle f, over the range b = [min, max]. M is the threshold value for the proposal distribution, such that f(x) < M for all x in b.

sampleDist(...,true) also generates a histogram of the results with an overlay of the true pdf.

Examples:
%Sample from a step function over [0,1]:
X = sampleDist(@(x)1.3*(x>=0&x<0.7)+0.3*(x>=0.7&x<=1),...
1.3,1e6,[0,1],true);
%Sample from a normal distribution over [-5,5]:
X = sampleDist(@(x) 1/sqrt(2*pi) *exp(-x.^2/2),...
1/sqrt(2*pi),1e6,[-5,5],true);

引用格式

Dmitry Savransky (2024). Simple Rejection Sampling (https://www.mathworks.com/matlabcentral/fileexchange/27590-simple-rejection-sampling), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2009b
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0