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() 可以从具有不同均值和标准差的


基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01