在给定log10平均值和log10标准差的情况下获得对数正态随机数 [英] Get lognormal random number given log10 mean and log10 standard deviation

查看:340
本文介绍了在给定log10平均值和log10标准差的情况下获得对数正态随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了 log-normal 分布的log10平均值和log10标准偏差.我想从此对数正态分布中获取一个随机数.

I am given the log10 mean and log10 standard deviation of a log-normal distribution. I want to get a random number from this log-normal distribution.

这可以用numpy.random.lognormal来完成,即使该函数的输入是基础正态分布的均值和标准(我没有)?

Can this be accomplished with numpy.random.lognormal, even though that function's inputs are the mean and standard of the underlying normal distribution (I do not have that)?

而且,我从函数中获得的随机数是log10,自然对数还是常规数?

Also, will the random number that I get back from the function be log10, natural log, or regular?

推荐答案

维基百科说对数正态分布的参数表示为基本正态分布,因此:

Wikipedia says that the parameters of lognormal distribution are expressed in terms of underlying normal distribution thus:

lognormal_mean = np.exp(normal_mean + normal_std**2 / 2)
lognormal_std = np.sqrt(np.exp(normal_std**2) - 1) * np.exp(normal_mean + normal_std**2 / 2)

使用一些代数可以将它们取反:

With a bit of algebra these can be reversed:

normal_std = np.sqrt(np.log(1 + (lognormal_std/lognormal_mean)**2))
normal_mean = np.log(lognormal_mean) - normal_std**2 / 2

然后您可以使用它们来生成样本.这是一个示例:

And then you can use those to generate a sample. Here is an example:

lognormal_mean = 3
lognormal_std = 5
normal_std = np.sqrt(np.log(1 + (lognormal_std/lognormal_mean)**2))
normal_mean = np.log(lognormal_mean) - normal_std**2 / 2
sample = np.random.lognormal(normal_mean, normal_std, size=10000000)
print(sample.mean(), sample.std())

在试运行中,输出为3.00126241708、4.999737569477-与参数3、5一致.

In a trial run, the output was 3.00126241708, 4.99737569477 - in agreement with the parameters 3, 5.

对数正态"中的对数"始终代表自然对数(以e为底),因此您将得到此结果.

The "log" in "lognormal" always stands for natural logarithm (base e), so this is what you will get.

最后,如果您输入的数据是log10(lognormal_mean)和log10(lognormal_std),那么第一步将是

Finally, if your input data is log10(lognormal_mean) and log10(lognormal_std) then the first step would be

lognormal_mean = 10**log10_lognormal_mean_
lognormal_std = 10**log10_lognormal_std


我还将检查源代码,以了解他们是否使用模棱两可的词组"log10 mean"来表示"log10 mean"或"log10 mean".如果它是"log10的平均值",那么您不需要上面的任何内容;您已经具有基本正态分布的参数,只需将它们乘以log(10)即可从log10转换为自然数.


I would also check the source to find if they use the ambiguous phrase "log10 mean" to mean "log10 of mean" or "mean of log10". If it was "mean of log10" then you don't need anything above; you already have the parameters of underlying normal distribution, they just need to be multiplied by log(10) to convert from log10 to natural.

这篇关于在给定log10平均值和log10标准差的情况下获得对数正态随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆