结合两个正常随机变量 [英] Combining two normal random variables
问题描述
假设我有以下2个随机变量:
suppose I have the following 2 random variables :
X,其中均值= 6,标准差= 3.5
Y,平均值= -42,stdev = 5
X where mean = 6 and stdev = 3.5
Y where mean = -42 and stdev = 5
我想基于前两个变量创建一个新的随机变量Z,并且知道:X发生90%的时间,Y发生10%的时间.
I would like to create a new random variable Z based on the first two and knowing that : X happens 90% of the time and Y happens 10% of the time.
计算Z的平均值很容易:0.9 * 6 + 0.1 * -42 = 1.2
It is easy to calculate the mean for Z : 0.9 * 6 + 0.1 * -42 = 1.2
但是有可能在单个函数中为Z生成随机值吗? 当然,我可以按照以下方式做一些事情:
But is it possible to generate random values for Z in a single function? Of course, I could do something along those lines :
if (randIntBetween(1,10) > 1)
GenerateRandomNormalValue(6, 3.5);
else
GenerateRandomNormalValue(-42, 5);
但是我真的很想拥有一个函数,该函数可以用作这样的随机变量(Z)的概率密度函数,而该变量不一定是正常的.
But I would really like to have a single function that would act as a probability density function for such a random variable (Z) that is not necessary normal.
对不起的伪代码
感谢您的帮助!
编辑:这是一个具体的询问:
Edit : here would be one concrete interrogation :
假设我们将Z的5个连续值的结果相加.以大于10的数字结束的概率是多少?
Let's say we add the result of 5 consecutives values from Z. What would be the probability of ending with a number higher than 10?
推荐答案
但是我真的很想有一个 单一功能 这样的概率密度函数 随机变量(Z)不是 必不可少的.
But I would really like to have a single function that would act as a probability density function for such a random variable (Z) that is not necessary normal.
好吧,如果您想要密度,这里是:
Okay, if you want the density, here it is:
rho = 0.9 * density_of_x + 0.1 * density_of_y
但是,如果不这样做,您将无法从该密度采样:1)计算其CDF(繁琐,但不可行)2)将其求逆(为此您将需要一个数值求解器).或者,您可以拒绝抽样(或其他形式,例如重要性抽样).这是昂贵的,而且要正确设置很麻烦.
But you cannot sample from this density if you don't 1) compute its CDF (cumbersome, but not infeasible) 2) invert it (you will need a numerical solver for this). Or you can do rejection sampling (or variants, eg. importance sampling). This is costly, and cumbersome to get right.
因此,您应该使用"if"语句(即,调用生成器3次),除非您有很强的理由不这样做(例如,使用准随机序列).
So you should go for the "if" statement (ie. call the generator 3 times), except if you have a very strong reason not to (using quasi-random sequences for instance).
这篇关于结合两个正常随机变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!