蒙特卡罗输入数据来自概率分布 [英] Monte Carlo Input Data from probability distribution

查看:85
本文介绍了蒙特卡罗输入数据来自概率分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试编写一些代码来运行蒙特卡罗模拟。我被困在第一位,需要为计算生成输入值。如果每个输入值都有概率分布,那么对于每次运行,我需要通过选择每次0到1之间的区域值来从该分布中选择值,其中分布下的区域被标准化为1.



有人能帮帮我吗?我一直在打猎几个小时,并没有真正到任何地方。我已经看过C中数字配方中的一些例子,但我不确定我所看到的是我需要什么。



我有以下想法,可能是或者可能没有任何正确的东西:



如果我有一个概率分布f(x),其中x从xmin到xmax,那么f(x)dx全部x = 1.



如果我选择一个随机区域值,例如0.3,我需要找到x,xval的值,它是曲线下面积为0.3的点。

所以我需要将f(x)从xmin整合到xval并将其等于0.3以便找到xval



例如如果f (x)= x ^ 2然后f(x)dx = x ^ 3/3

所以(xval ^ 3 - xmin ^ 3)/ 3 = 0.3然后我只需要找到xval



这是对吗?

如果是这样,我只需找到所有概率分布的综合公式

例如如果我的分布是x ^ 2那么我不需要知道这个,我只需要知道我的综合公式是x ^ 3/3





感谢您花时间阅读本文。

Hi,

I am trying to write some code to run a Monte Carlo simulation. I am stuck on the first bit which requires the generation of input values to the calculations. If each input value has a probability distribution, for each run I need to pick values from this distribution by choosing an area value between 0 and 1 each time, where the area under the distribution is normalized to be 1.

Can anyone help me? I have been hunting for several hours and have not really got anywhere. I have looked at some examples in numerical recipes in C but am not sure if what I am looking at is what I need.

I have the following thoughts, which may or may not have anything correct in them:

If I have a probability distribution f(x), where x goes from xmin to xmax, then f(x)dx over all x = 1.

If I pick a random area value, e.g. 0.3, I need to find the value of x, xval, which is the point at which the area under the curve is 0.3.
So I need to integrate f(x) from xmin to xval and equate that to 0.3 in order to find xval

Eg if f(x) = x^2 then f(x)dx = x^3/3
So (xval^3 – xmin^3)/3 = 0.3 then I just need to find xval

Is this right?
If so, I just need to find the integrated formula for all the probability distributions
e.g. if my distribution is x^2 then I don’t need to know this, I just need to know that my integrated formula is x^3/3


Thank you for taking the time to read this.

推荐答案

实际上,您所指出的是正确的。



从具有累积分布函数 F(x)的概率分布中绘制值 x 的正式方法是随机选择a值 y 在0和1之间的统一概率法然后做:



x = F(-1)(y)



其中 F(-1) F 的反函数,即:



x = F(-1)(y)< => y = F(x)



但是为了从概率分布中提取值,并不总是需要获得 F 。如果您的人口来自普通(高斯)概率定律,那么使用 Box-Müller算法会更容易:



/>


1.-从 U [0,1] 中选择一个值 u ([u>概率统一定律] 0,1])。

2.-从 U [0,1] 中选择另一个值 v ([0]中的概率统一定律0,1])。

3.-从 N(mu,sigma)(高斯平均值绘制值 x mu 和标准差 sigma )根据以下公式:



x = mu + sigma * square_root(2 * ln( 1 /(1 - u)))* cos(2 * PI * v)



ln 是neperian对数a PI 是3.141592 ...



我希望这有帮助
In effect, what you have pointed out is correct.

The formal way to draw a value x from a probability distribution with a cumulative distribution function F(x) is by randomly choosing a value y between 0 and 1 in a uniform law of probability and then doing:

x = F(-1)(y)

where F(-1) is the inverse function of F, i.e:

x = F(-1)(y) <=> y = F(x)

But it is not always necessary to obtain F in order to draw a value from a probability distribution.

If your population comes from a normal (gaussian) law of probability, it is much easier to use the Box-Müller algorithm:

1.- Choose a value u from a U[0,1] (uniform law of probability in [0, 1]).
2.- Choose another value v from a U[0,1] (uniform law of probability in [0, 1]).
3.- Draw a value x from a N(mu, sigma) (gaussian with mean mu and standard deviation sigma) according to the following formula:

x = mu + sigma * square_root(2 * ln(1 / (1 - u))) * cos(2 * PI * v)

ln is neperian logarithm an PI is 3.141592...

I hope this helps


这篇关于蒙特卡罗输入数据来自概率分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆