4

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

4

3 回答 3

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);
于 2012-11-04T11:45:25.203 回答
1

支持指数分布[0,+\infty)。您可能希望[0,1)使用一些可测量的可逆映射重新映射它f,因此这Y = f(X)是支持的随机变量[0,1)

问题:你必须构建这样一个f.

我的建议是

 f(x) = 2/pi * arctan(x). 

该函数arctan映射(-\infty,\infty)(-pi/2,pi/2)。因为您只考虑正样本(因为您X呈指数级增长),所以您将获得样本[0,pi/2);因此,您必须重新调整2/pi. 此外,由于 is 的 MacLaurin 展开式arctanx+o(x)您的样本与原点呈指数地完全接近。

现在,如果您从任何指数中采样(即使用可能的任何值\lambda- 最好是小的)并且您对样本进行评估f,您将获得随心所欲地集中的样本(即接近0和接近指数)。

于 2012-11-04T11:45:41.813 回答
0

这里有一个建议:

从 lambda=1 的指数分布中采样,并拒绝超出预期区间的任何数字。如果您的区间是 [0,1],那么您在该区间内获得一个数字的概率约为 0.63。这意味着在 10 个样本后获得“好”数字的概率为 99%。

另一种可能性是选择一个足够高的数 n,使得在 n 上采样某样东西的概率足够小。对于 lambda = 1,n=1000 就足够了。然后您只需从指数中采样并将其转换为您的随机样本 a+(ba)*(sample/n)

于 2012-11-04T11:40:29.447 回答