首页 文章

Random.nextgaussian()可以从具有不同均值和标准差的分布中采样值吗?

提问于
浏览
15

这是一个综合的Java和基本数学问题 . 来自Random.nextGaussian()的文档声明它从正态分布中采样,均值为0,标准差为1.如果我想从具有不同均值和方差的正态分布中进行采样,该怎么办?

1 回答

  • 35

    简短的回答是

    Random r = new Random();
    double mySample = r.nextGaussian()*desiredStandardDeviation+desiredMean;
    

    例如,这里给出了答案:http://www.javamex.com/tutorials/random_numbers/gaussian_distribution_2.shtml

    我真的不明白为什么会这样有效,但在调查之后我想我已经弄明白了 . 样本点的均值为0,标准差为1;这意味着原始样本也是它自己的z分数(https://en.wikipedia.org/wiki/Standard_score) . 引用维基百科"The absolute value of z represents the distance between the raw score and the population mean in units of the standard deviation" . 公式为z =(x-mean)/ stdev,因此默认值为z = x . 如果我们想保留样本的z分数但是改变平均值和stdev我们会做什么?

    z * stdev mean = x',其中z = x,x'表示具有所需平均值和标准偏差的分布中的样本 .

相关问题