具有指数分布的特定区间中的随机数

时间:2012-11-04 11:24:43

标签: matlab math probability

我想使用指数分布在特定区间内生成一个随机数。我的问题是如果我使用exprnd我无法控制间隔,我只能给出一个平均值,但这不符合我的需要。 还有其他功能还是我必须使用一些技巧?

3 个答案:

答案 0 :(得分:2)

这有帮助吗? (或者我误解了这个问题?)

%#Set the parameters
T = 2000; %#Number of observations to simulate
Mu = 0.5; %#Exponential distribution parameter
LB = 0; %#Lower bound on exponential distribution
UB = 1; %#Upper bound on exponential distribution

%#Validate the parameters
if LB < 0 || UB < 0; error('Bounds must be non-negative'); end
if Mu <= 0; error('Mu must be positive'); end

%#Determine LB and UB in terms of cumulative probabilities
LBProb = expcdf(LB, Mu);
UBProb = expcdf(UB, Mu);

%#Simulate uniform draws from the interval LBProb to UBProb
Draw = LBProb + (UBProb - LBProb) .* rand(T, 1);

%#Convert the uniform draws to exponential draws using the inverse cdf
X = expinv(Draw, Mu);

答案 1 :(得分:1)

[0,+\infty)支持指数分布。您可能希望使用[0,1)可翻转地图fY = f(X)上重新映射,以便[0,1) f支持随机变量。

问题:您必须构建这样的 f(x) = 2/pi * arctan(x).

我的建议是

arctan

函数(-\infty,\infty)(-pi/2,pi/2)映射到X。因为您只考虑正样本(因为您的[0,pi/2)呈指数级),您将获得2/pi中的样本;因此,您必须按arctan重新缩放。此外,由于x+o(x)的MacLaurin扩展为\lambda,因此您可以获得与原点完全指数接近的样本。

现在,如果您从任何指数(即可能使用f的任何值 - 最好是小)进行采样,并且您在样本上评估0,那么您可以获得随意集中的样本(即关闭)到{{1}}并且几乎呈指数级。)

答案 2 :(得分:0)

这是一个建议:

来自指数分布的样本,其中lambda = 1,并拒绝超出预期间隔的任何数字。如果您的间隔为[0,1],则在该间隔内获得一个数字的概率为~0.63。这意味着在10个样本之后获得“好”数字的概率为99%。

另一种可能性是选择足够高的数n,使得在n上取样的概率足够小。对于lambda = 1,n = 1000就足够了。然后你只需从指数中取样并通过+(b-a)*(样本/ n)将其转换为随机样本

相关问题