Can Random.nextgaussian() sample values from a distribution with different mean and standard deviation?(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() 可以从具有不同均值和标准差的
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01