Random.nextgaussian() 可以从具有不同均值和标准差的

Can Random.nextgaussian() sample values from a distribution with different mean and standard deviation?(Random.nextgaussian() 可以从具有不同均值和标准差的分布中采样值吗?)

本文介绍了Random.nextgaussian() 可以从具有不同均值和标准差的分布中采样值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一道结合 Java 和基本数学的问题.Random.nextGaussian() 的文档指出它从均值为 0 和标准差为 1 的正态分布中采样.如果我想从具有不同均值和方差的正态分布中采样怎么办?

This is a combined Java and basic math question. The documentation from Random.nextGaussian() states that it samples from a normal distribution with mean 0 and standard deviation 1. What if I wanted to sample from a normal distribution with a different mean and variance?

推荐答案

简短的回答是

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

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

For example this answer is given here: http://www.javamex.com/tutorials/random_numbers/gaussian_distribution_2.shtml

我真的不明白为什么会这样,但在仔细研究之后我想我明白了.样本点的均值为0,标准差为1;这意味着原始样本也是它自己的 z-score ( https://en.wikipedia.org/wiki/Standard_score ).引用维基百科的z 的绝对值表示原始分数与总体平均值之间的距离,以标准差为单位".公式为 z=(x-mean)/stdev,因此使用默认值 z=x.如果我们想保留样本的 z 分数但改变均值和标准差,我们会怎么做?

I didn't really understand why this worked, but after looking into it a bit I think I figured it out. The mean of the sample point is 0, and the standard deviation is 1; that means that the original sample is also its own z-score ( https://en.wikipedia.org/wiki/Standard_score ). To quote from wikipedia "The absolute value of z represents the distance between the raw score and the population mean in units of the standard deviation". The formula is z=(x-mean)/stdev, so with the default values z=x. If we wanted to retain the z score for the sample but change the mean and stdev what would we do?

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

z*stdev + mean = x' where z=x, and x' represents the sample from the distribution with the desired mean and standard deviation.

这篇关于Random.nextgaussian() 可以从具有不同均值和标准差的分布中采样值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Random.nextgaussian() 可以从具有不同均值和标准差的

基础教程推荐