w*******1 发帖数: 112 | 1 random number generator generates standard normal variable x. how to use
monte carlo simulation and importance sampling to find the prob(x>10)? thank
you very much |
l******n 发帖数: 9344 | 2 N = 10000
alpha = 10
set.seed(12345)
samples = alpha-log(1-runif(N))
z = 1/(sqrt(2*pi))*exp(-alpha)*exp(samples-samples^2/2)
mean(z)
sd(z)
thank
【在 w*******1 的大作中提到】 : random number generator generates standard normal variable x. how to use : monte carlo simulation and importance sampling to find the prob(x>10)? thank : you very much
|
w*******1 发帖数: 112 | 3 能稍微解释下思路么?多谢,多谢
【在 l******n 的大作中提到】 : N = 10000 : alpha = 10 : set.seed(12345) : samples = alpha-log(1-runif(N)) : z = 1/(sqrt(2*pi))*exp(-alpha)*exp(samples-samples^2/2) : mean(z) : sd(z) : : thank
|
K*****Y 发帖数: 629 | 4 题目是已经给定可以生成standard normal random variable x, 所以不清楚为什么楼
上的解法还要用到 1/(sqrt(2*pi))和对数变换,感觉用不着这么麻烦。
用R测试并写的程序:
N=10000 # number of random samples, which can be specified
x=rnorm(N) # generate N standard normal random variables
alpha=10 # calculate P(x>alpha)
est=mean(as.numeric(x>0)*exp(-alpha*x-0.5*alpha^2)) #est gives the required
value
思路很简单。要求P(x>alpha),E[1_{x>alpha}],做一个变换x'=x-alpha,也就是要求
期望值E{1_{x'>0}*w(x')},其中w(x')=exp(-alpha*x'-0.5*alpha^2) is the weight
function, 也就是新旧变量的likelihood ratio。自己写一下积分推导一下很容易得到
。 |
m****r 发帖数: 141 | 5 est=mean(as.numeric(x>0)*exp(-alpha*x-0.5*alpha^2))
should be
est=mean(as.numeric(x>0)*exp(-x^2/2-alpha*x-0.5*alpha^2))
right?
required
weight
【在 K*****Y 的大作中提到】 : 题目是已经给定可以生成standard normal random variable x, 所以不清楚为什么楼 : 上的解法还要用到 1/(sqrt(2*pi))和对数变换,感觉用不着这么麻烦。 : 用R测试并写的程序: : N=10000 # number of random samples, which can be specified : x=rnorm(N) # generate N standard normal random variables : alpha=10 # calculate P(x>alpha) : est=mean(as.numeric(x>0)*exp(-alpha*x-0.5*alpha^2)) #est gives the required : value : 思路很简单。要求P(x>alpha),E[1_{x>alpha}],做一个变换x'=x-alpha,也就是要求 : 期望值E{1_{x'>0}*w(x')},其中w(x')=exp(-alpha*x'-0.5*alpha^2) is the weight
|
K*****Y 发帖数: 629 | 6 No. The quadratic term should not be there.
Suppose alpha=0, then in principal the answer should be 0.5 (est will just
be mean(as.numeric(x>0)). But your solution will give some value around 0.
35.
【在 m****r 的大作中提到】 : est=mean(as.numeric(x>0)*exp(-alpha*x-0.5*alpha^2)) : should be : est=mean(as.numeric(x>0)*exp(-x^2/2-alpha*x-0.5*alpha^2)) : right? : : required : weight
|