+ Reply to Thread
Results 1 to 14 of 14

Thread: Monte carlo conditioning

  1. #1
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Monte carlo conditioning



    I am trying to learn how to reduce variance with conditioning. page 15 in these lecture notes:
    http://www.columbia.edu/~mh2078/MCS_Var_Red1.pdf

    The notes has only one example(page 16) and I'm not how to transfer it to other integrals

    If I want to calculate the integral
    I integral exp(x)*sin(2*pi*x) dx
    from 0 to 1.

    Then what should be my conditioning expression? I know I'm supposed to have shown my work before posting, but I'm stuck at the beginning.

    With condition expression I mean the form E(E(Y|Z)) as they use in the notes.

  2. #2
    Probably A Mammal
    Points: 14,473, Level: 78
    Level completed: 6%, Points required for next Level: 377
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    1,952
    Thanks
    221
    Thanked 419 Times in 387 Posts

    Re: Monte carlo conditioning

    I don't see where you're supposed to calculate any integral. The steps are pretty straight-forward

    (1) Generate samples, all independent
    (2) Set Yi to the specified transformation
    (3) Estimate the parameter with the mean
    (4) Calculate confidence intervals

    You need to know (1) and (2). The rest is computational. You need to know what distributions your samples are coming from (as in the example, U and Z were from specified distributions). Then you need to know the transformation that defines Y (as in the example, it was I_{U + Z > 4}). The author then shows how to use conditioning method to instead solve V (a transformation on Y, based on Z, now).

    I don't understand what you're trying to solve with this step since the method was not simulating integration. It's simulating an estimate with a reduction in variance.

  3. The Following User Says Thank You to bryangoodrich For This Useful Post:

    alf (11-23-2011)

  4. #3
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Thanks for answering, English is not my first language so maybe I'm unclear or reading your post wrong.
    I'm trying to use conditional monte carlo to
    calculate the integral:
    integral exp(x)*sin(2*pi*x) dx
    from 0 to 1.

    I don't see how to use your algorithm to solve this integral.

    Monte carlo
    l = E(H(X)) = integral H(x)f(x) dx

    Conditional monte carlo
    Generate samples Y1,...Yn form g(y), the distribution to Y
    Calculate E(H(X)|Y_k) k = 1,...,N analytically
    Estimate l = H(X) by
    l_hat = (1/N) sum^N E(H(X)|Y_k)

    But how do I do this with my integral?

  5. #4
    TS Contributor
    Points: 14,827, Level: 78
    Level completed: 95%, Points required for next Level: 23

    Posts
    2,297
    Thanks
    8
    Thanked 372 Times in 351 Posts

    Re: Monte carlo conditioning

    I think in \int_0^1 e^x \sin(2\pi x)dx, since the exponential function is non-negative and is bounded on [0, 1], you may consider ce^x as a probability density function (where c is a constant and let you find out), and simulate X accordingly by inverse transform, and eventually you can use it to estimate the sample mean \frac {1} {c} \sin(2\pi X).

  6. #5
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Thanks, I'm not sure if I understand the algorithm, you take the integral exp(x)*sin(2*pi*x), take the part that could be thought of as a pdf, then let x be sampled from this distribution and use montecarlo on the other part(sin(2*pi*x)). But how do you see that e^x sin(2*pi*x),x uniformly distributed has the same mean as (1/c) sin(2*pi*x), x ce^x distributed?

    pdf = c
    cdf =
    The cdf has to be 1 at x=1




    To sample from X according to the inverse transform





    *should be (y+c)/c, + doesn't work in my latex
    where y is uniformly distributed on [0,1]

    so use montecarlo on (1/c) sin(2*pi*X)

    right?

  7. #6
    TS Contributor
    Points: 14,827, Level: 78
    Level completed: 95%, Points required for next Level: 23

    Posts
    2,297
    Thanks
    8
    Thanked 372 Times in 351 Posts

    Re: Monte carlo conditioning

    Yes, it is fine. This is just the most trivial distribution (the truncated exponential) for this question.

  8. #7
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Great. But how do you see that e^x sin(2*pi*x),x uniformly distributed has the same mean as (1/c) sin(2*pi*x), x ce^x distributed?

    And I have also a question about the terms one use. Sometimes they say conditioning on the x variable. But what does that mean? In this case we conditioned on the function e^x?. Or do we say that we conditioned on the x variable?
    Does conditioning on the x variable only makes sense when we have multi variables? f = exp(xy)sin(x)? what would it mean to condition on the x variable here?

  9. #8
    RotParaTon
    Points: 46,187, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,069
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: Monte carlo conditioning

    Quote Originally Posted by alf View Post
    Great. But how do you see that e^x sin(2*pi*x),x uniformly distributed has the same mean as (1/c) sin(2*pi*x), x ce^x distributed?
    If you were told that X has a truncated exponential distribution ( f(x) = ce^x for 0<= x <= 1) and you wanted to know E[(1/c) sin(2*pi*x)] how would you calculate it?
    If you were told that X has a uniform distribution ( f(x) = 1 for 0 <= x <= 1) and you wanted to know E[e^x sin(2*pi*x)] how would you calculate it?

  10. #9
    TS Contributor
    Points: 14,827, Level: 78
    Level completed: 95%, Points required for next Level: 23

    Posts
    2,297
    Thanks
    8
    Thanked 372 Times in 351 Posts

    Re: Monte carlo conditioning

    Actually I have not click into the notes you posted on the 1st post before my 1st reply above - I only think you are trying to estimate the integral as an exercise. Here in the question you proposed there is no obvious variable for you to condition on - I think this technique generally referred to the stratified sampling.

    I can provide some calculations for you to let you have a feeling.
    First of all by simple integration (by part twice) you can show that the theoretical values

    \int_0^1 e^x \sin(2\pi x)dx = \frac {-2\pi (e - 1)} {4\pi^2 + 1}

    If X follows the truncated exponential, then

    Var[(e - 1)\sin(2\pi X)] = \frac {4(e-1)^2\pi^2(32\pi^4 + 1)} {256\pi^6 + 144\pi^4 + 24\pi^2 + 1} \approx 1.395818638

    If X follows the uniform(0, 1), then

    Var[e^X\sin(2\pi X)] = \frac {4\pi^2[(e^2-1)\pi^2-3e^2+8e-5]} {16\pi^4 + 8\pi^2 + 1} \approx 1.388706935

    So the estimator suggested by me is not as good as the one you simulate by the uniform.

    One thing here is that you can choose a good density for you to reduce the variance - which is also generally known as the importance sampling.

  11. #10
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Quote Originally Posted by Dason View Post
    If you were told that X has a truncated exponential distribution ( f(x) = ce^x for 0<= x <= 1) and you wanted to know E[(1/c) sin(2*pi*x)] how would you calculate it?
    If you were told that X has a uniform distribution ( f(x) = 1 for 0 <= x <= 1) and you wanted to know E[e^x sin(2*pi*x)] how would you calculate it?
    Thanks
    E[(1/c) sin(2*pi*x)] = integral (1/c) sin(2*pi*x) c e^x dx = integral sin(2*pi*x) e^x dx
    E[e^x sin(2*pi*x)] = integral e^x sin(2*pi*x) dx

  12. #11
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Quote Originally Posted by BGM View Post
    Actually I have not click into the notes you posted on the 1st post before my 1st reply above - I only think you are trying to estimate the integral as an exercise. Here in the question you proposed there is no obvious variable for you to condition on - I think this technique generally referred to the stratified sampling.

    I can provide some calculations for you to let you have a feeling.
    First of all by simple integration (by part twice) you can show that the theoretical values

    \int_0^1 e^x \sin(2\pi x)dx = \frac {-2\pi (e - 1)} {4\pi^2 + 1}

    If X follows the truncated exponential, then

    Var[(e - 1)\sin(2\pi X)] = \frac {4(e-1)^2\pi^2(32\pi^4 + 1)} {256\pi^6 + 144\pi^4 + 24\pi^2 + 1} \approx 1.395818638

    If X follows the uniform(0, 1), then

    Var[e^X\sin(2\pi X)] = \frac {4\pi^2[(e^2-1)\pi^2-3e^2+8e-5]} {16\pi^4 + 8\pi^2 + 1} \approx 1.388706935

    So the estimator suggested by me is not as good as the one you simulate by the uniform.

    One thing here is that you can choose a good density for you to reduce the variance - which is also generally known as the importance sampling.
    So you only stratify on variable not conditioning on variables?

    But in the lecture notes it seems like you can't get higher variance when you condition, then how does we get it here?
    Last edited by alf; 11-24-2011 at 06:40 PM.

  13. #12
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Another question, lets say I want to compute the integral(fro 0 to 1) of exp(xy)sin(2*pi*x) and use stratification. Is this correct:
    The idea behind stratification is to divide the integral in several parts so that the integral does not change as much in each interval.
    In this integral is it just the same if I stratify on the x variable or the y variable or can you see that one is bether than thee other? I realise that I can compute the integral and check the variance and it is maybe possible to stratify on both, but I want to know if you can see it on the form of the function. And is it possible to see how you should choose the intervals?

    If I stratify on the x variable and divide it in two parts from 0 to 1/2 and 1/2 to 1, the code in R becomes:

    n = 100
    f = function(x,y){exp(x*y)*sin(2*pi*x)}
    y = runif(n/2) # generate n/2 uniform variables from 0 to 1
    x1 = runif(n/2,0,.5) # generates n/2 uniform variables from 0 to 1
    x2 = runif(n/2,.5,1) # generates n/2 uniform variables from 0 to 1
    H1 = f(x1,y)
    y = runif(n/2) # the same as y earlier, but generates new random variables
    H2 = f(x2,y)
    I = mean(H1+H2) # the integral is the mean of H1 and H2
    V = var(H1+H2) # The variance of the montecarlo integral is the variance of H1 + H2

    It seems like I get the wrong integral
    Is it wrong to generate y two times with n/2 variables in each?

  14. #13
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning

    Another question about conditioning. If I have exp(xy)*sin(2*pi*x), is it possible to condition on f = sin(2*pi*x)? f is both positive and negative on the interval 0 to 1 so it is not a pdf, but is it possible to do some kind of transformation or something? Are you allowed to write it as f1 =A+Bsin(2*pi*x), where A and B are chosen such that it becomes a pdf. The B should be fine because that was what BGM did, but what about A?

  15. #14
    Points: 1,019, Level: 17
    Level completed: 19%, Points required for next Level: 81

    Posts
    33
    Thanks
    6
    Thanked 2 Times in 1 Post

    Re: Monte carlo conditioning


    It seems like it is not possible to use A+ B sin(2*pi*x) anyway

    The integral becomes Ax - (B/2*pi)*cos(2*pi*x). For x = 1 this integral has to be 1, but that means A = 1 and then the only possible B that makes the integral smaller than 1 becomes 0.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats