本文介绍了产生N名单(严格正)值,使得该列表有predetermined意味着x和性病。开发。 ÿ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想产生N严格正值使得列表具有predetermined均值和标准差的名单(可关闭/不准确)。我用的是均匀分布的方程期望和方差,解决了'一'和'B',而方程组(为特定的平均值和标准型的开发者,我想)没有解决方案的A,B> = 0我在想,如果有一个插件和突突的方法来做到这一点任何编程语言,但希望在Python。谢谢!

I would like to generate a list of n strictly positive values such that the list has a predetermined mean and standard deviation (can be close/not exact). I was using the uniform distribution's equations for expectation and variance and solving for 'a' and 'b', but the system of equations (for the specific mean and std. dev. I wanted) had no solutions for a, b >= 0. I was wondering if there was a plug-and-chug method to do this in any programming language, but hopefully in Python. Thanks!

例如:产生,平均〜= = 60/84 0.71,std.dev 84正值列表。 〜= 1.7

Ex: generate list of 84 positive values with mean ~= 60/84 = 0.71, std.dev. ~= 1.7

推荐答案

使用 NumPy的来生成样本与尺度参数THETA gamma分布=方差/均值和形状参数k =平均/ THETA。

Answer

Use NumPy to generate samples from a gamma distribution with scale parameter theta = variance / mean and shape parameter k = mean / theta.

>> import numpy

>> mu = 0.71
>> var = 1.7**2 
>> theta = var / mean 
>> k = mu / theta

>> samples = numpy.random.gamma(k, theta, 1000)

>> numpy.mean(samples)
0.71622189354608201

>> numpy.std(samples) 
1.7865898752966483

评论

您提供underspecify分布的约束。你的一些针对提出的意见,以另一个答案将是有帮助的问题的一部分。特别是,它好像你可能试图来港定居人士模拟了长龙,如泊松过程。如你指出,的均值和泊松分布的方差是相同的,在lambda参数。但是,应考虑拉姆达本身作为一个随机变量。缀合物之前的泊松分布Gamma分布

Commentary

The constraints you provide underspecify the distribution. Some of the comments you made in response to another answer would have been helpful as part of the question. In particular, it seems as if you might be trying to model arrivals in a queue, e.g. a Poisson process. As you pointed out, the mean and variance of a Poisson distribution are the same, the lambda parameter. However, consider the lambda itself as a random variable. The conjugate prior to the Poisson distribution the Gamma distribution.

使用形状参数k> 0,尺度参数THETA> 0时,伽玛分布有意味= K * theta和方差= K * THETA ^ 2。因此,THETA是方差/均值> 0,k为平均/ THETA> 0。由于伽玛分布具有积极的支持,这方便回答你的问题。

With shape parameter k > 0 and scale parameter theta > 0, the gamma distribution has mean = k * theta and variance = k * theta^2. Therefore, theta is variance / mean > 0 and k is mean / theta > 0. Since the gamma distribution has positive support, this conveniently answers your question.

这篇关于产生N名单(严格正)值,使得该列表有predetermined意味着x和性病。开发。 ÿ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 04:24