简体   繁体   English

从Java中的数组生成对数正态分布

[英]Generating a lognormal distribution from an array in Java

I didn't find any help on the subject so I'm posting a new question about it. 我没有找到任何有关此主题的帮助,因此我发布了一个有关此问题的新问题。 I have a variable containing three values {min, average, standard dev.}. 我有一个变量,包含三个值{min,平均值,标准dev。}。 How do I generate a lognormal distribution of this array that would randomly give me a value of the time from the lognormal distribution. 如何生成此数组的对数正态分布,该分布将随机为我提供对数正态分布的时间值。 Also If I would run it 1000 times I would want to randomly get a value of the time from the lognormal distribution each of the 1000 times. 另外,如果我将其运行1000次,则希望从1000次对数正态分布中随机获取时间值。 How would I write this in java code? 我将如何用Java代码编写此代码? Also I guess running it 1000 times would give me an average of the average in the array? 另外我猜它运行1000次会得到数组中平均值的平均值吗?

First generate standard normal values and convert them to normal distribution with given parameters. 首先生成标准正态值,并将其转换为具有给定参数的正态分布。 Finally raise to exponential to get log-normal distribution with given mean and std dev. 最后提高到指数以获得具有给定的均值和标准差的对数正态分布。

Random rng = new Random(0);
double[] lognormalValues = new double[1000];

for (int i = 0; i < 1000; ++i)
{
    stdNormal   = rng.nextGaussian();
    normalValue = stddev*stdNormal + mean;

    logNormalValues[i] = Math.exp(normalValue);
}

you can also get a built in function here. 您还可以在此处获得内置功能。 in your above example, you won't actually end up with the stddev and mean noted -- they change when you exp() the values. 在上面的示例中,您实际上不会以stddev和均值结尾-当您对exp()值进行更改时,它们会更改。

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/distribution/LogNormalDistribution.html http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/distribution/LogNormalDistribution.html

or this 或这个

public static double LogNormal(double mean, double stddev) {
    Random randGen = new Random();
    double varx = Math.pow(stddev, 2);
    double ess = Math.log(1.0 + (varx/Math.pow(mean,2)));
    double mu = Math.log(mean) - (0.5*Math.pow(ess, 2));
    return Math.pow(2.71828, (mu+(ess*randGen.nextGaussian() ) ) );

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM