3

Use simulation with antithetic variables to find

$$\int_{-\infty}^{\infty} \int_0^\infty\, \sin(x+y)e^{-x^2+4x-y}\,dx\,dy.$$ My question is, how struggle with the infinite limit?

It is easy for me to solve similar problems like $\int_0^1e^x\,dx$, but I do not know how to do the stated one.

whuber
  • 281,159
  • 54
  • 637
  • 1,101
albert
  • 303
  • 1
  • 11
  • I'm confused, do you want an analytical solution for the integral or do you want how to calculate it numerically through simulation? –  Nov 25 '15 at 01:31
  • no analytical, with antithetic variables – albert Nov 25 '15 at 01:33
  • 2
    I think to calculate this format of double integrate is not difficult ( interchange order of integration then integrate by parts) but the limits $-\infty $ to $\infty$ is problematic it will cause the integral divergent. – Deep North Nov 25 '15 at 01:35
  • 1
    @DeepNorth is correct. The intergral is divergent. –  Nov 25 '15 at 01:39
  • `http://www.wolframalpha.com/input/?i=integral_-infty^infty+integral_0^infity+sin%28x%2By%29*e^%28x^2%2B4x-y%29+dx+dy` –  Nov 25 '15 at 01:39
  • this integral is approximately 18.58 but I need to calculate the antithetic variables method – albert Nov 25 '15 at 01:45
  • How did you get 18.58? –  Nov 25 '15 at 02:02
  • integrating in r – albert Nov 25 '15 at 02:05
  • 1
    @albert does `R` tell you when an integral is divergent? I fear that it might just output whatever numerical solution it thinks it should be even if the answer does not exist. –  Nov 25 '15 at 02:45
  • Check your calculations because this integral converges – albert Nov 25 '15 at 02:56
  • Can you please provide your `R` code? –  Nov 25 '15 at 03:16
  • 4
    This double integral involves *three* limits. It *obviously* does not converge for two of those limits (as $y\to-\infty$ and $x\to\infty$). Any numerical answer you might obtain will be pure garbage. – whuber Nov 25 '15 at 13:49
  • 1
    The modified version of the integral will no longer have problems converging in $x$, but the lower limit of $-\infty$ for $y$ is still of concern. Did you perhaps interchange the limits (or the variables) in typesetting the integral? – whuber Nov 25 '15 at 20:06

2 Answers2

6

Overview

The method of antithetic variables is a way to increase the precision of a Monte-Carlo estimate of an integral by finding a way to balance the large values with equally likely small values. The resulting negative correlation reduces the variance of the estimate.

One context in which this tends to work concerns finding expectations. A Monte-Carlo method to find the expectation of any function $g$ of a random variable $X$ is to draw a sequence of independent realizations $x_1, x_2, \ldots, x_n$ according to the probability law $F$ of $X$ and simply average the value of $g$ at these points:

$$\mathbb{E}(g(X)) = \int_\mathbb{R} g(x) dF(x) \approx \frac{1}{n}\sum_{i=1}^n g(x_i).$$

Often, especially for continuous distributions, the desired balance of large against small values can be achieved by pairing each $x_i$, with its antithetic value $x_i^{*}$. This is the number having the complementary quantile of $x_i$; that is,

$$F(x_i) + F(x_i^{*}) = 1.$$

This example

We can recognize the germs of probability distribution functions in the terms $\exp(-x^2 + 4 x)$ and $\exp(-y)$ within the integral because

  • Each is non-negative and

  • Each has a finite integral: $\exp(-x^2 + 4x) = \exp(-(x-2)^2)\exp(4)$ over the entire set of real numbers, which evaluates to $\exp(4)\sqrt{\pi}$, and $\exp(-y)$ over the positive real numbers, which evaluates to $1$.

This suggests rewriting the integral as

$$\int_0^\infty \int_{-\infty}^{\infty} \sin(x+y) \exp(-x^2 + 4x - y) \mathrm{dx\, dy} = \exp(4)\sqrt{\pi}\,\mathbb{E}(\sin(X+Y))$$

where $X$ has a Normal$(2, \sqrt{1/2})$ distribution and $Y$ has an Exponential distribution.

One step of the numerical integration, then, could proceed as follows:

  1. Draw uniform$(0,1)$ random variables $U, V$ independently.

  2. Compute the $U$ quantile of a Normal$(2, \sqrt{1/2})$ distribution as $X$ and the $1-U$ quantile of that distribution as $X^{*}$.

  3. Compute the $V$ quantile of an Exponential distribution as $Y$ and the $1-V$ quantile of that distribution as $Y^{*}$.

  4. Compute $g = \sin(X + Y)$ and $g^{*} = \sin(X^{*} + Y^{*})$.

That produces two values for the eventual average that will be used for the numerical estimate of the integral.

Let's check that this is going to work by computing the correlation between $g$ and $g^{*}$ for a large number of iterations. Here is a plot for $10,000$ iterations:

Figure 1: Scatterplot

The large negative correlation indicates this method will work well.

As a fair comparison to a straight Monte-Carlo integration, consider what could be accomplished with $N=1000$ iterations. With antithetic variables we would compute just $N/2=500$ pairs of realizations $(x_i,y_i)$ and use their antithetic counterparts $(x_i^{*}, y_i^{*})$ for the other $500$. Otherwise, we would compute $1000$ sets of $(x_i, y_i)$. Both methods take essentially the same computational effort.

If we were to do this, say, $10,000$ times, we would obtain $10,000$ estimates of the integral with each method. The better method is the one whose estimates range more tightly around the true value. Here are histograms of the two sets of estimates--blue for Monte-Carlo, red for the antithetic version--along with a vertical line locating the value of the integral (at $\exp(15/4)\sqrt{\pi}\,(\cos(2)+\sin(2))/2 \approx 18.5836$.) The superiority of the antithetic method is clear.

Figure 2: Histograms of sampling distributions

The standard deviation of the antithetic method is less than half the SD of the simple method in this case. Equivalently, to achieve any given precision in the estimate requires less than one quarter as much computational effort with the antithetic method (in this example).

Comments

Where did the problem with infinite limits of integration go to? It was handled by the underlying probability distributions.

Note that we can learn about how much better the antithetic method is for any given situation by testing it with a relatively small number of iterations. These results can be used to determine in advance how much computation to devote to the actual calculation.

I implicitly assumed the limits of integration were mixed up in the statement of the problem, for otherwise the integral, as written, diverges.

Code

This R code created the figures. It illustrates how to use the method of antithetic variables. Timing statements confirm that both it and the simple method take the same amount of computational effort.

#
# Compute values of the integrand, given equal-length vectors of uniform 
# variates `u` and `v`.
#
g <- function(u, v) {
  x <- qnorm(u, 2, sqrt(1/2))
  y <- qexp(v)
  exp(4) * sqrt(pi) * sin(x + y)
}
#
# Estimate the integral in two ways, repeatedly.
#
N <- 1e3 / 2
system.time(sim1 <- replicate(1e4, {
  u <- runif(N); v <- runif(N)
  mean(g(c(u, 1-u), c(v, 1-v))) # Antithetical method
}))
system.time(sim2 <- replicate(1e4, {
  u <- runif(2*N); v <- runif(2*N)
  mean(g(u,v))                  # "Simple" method
}))
#
# Plot the histograms of each method.
#
par(mfrow=c(1,1))
hist(sim2, freq=FALSE, breaks=20, ylim=c(0, 0.75*sqrt(N/1000)), col="#5b5be0b0",
     xlab="Estimate", main="Histograms of estimates")
hist(sim1, freq=FALSE, breaks=20, add=TRUE, col="#e05b5bb0")
abline(v = exp(15/4) * sqrt(pi) * (cos(2) + sin(2))/2, lwd=2)
#
# Study the correlation of the antithetic variables.
#
u <- runif(1e4); v <- runif(1e4)
g0 <- g(u, v)
g1 <- g(1-u, 1-v)
plot(g0, g1, asp=1, pch=16, col="#00000020", cex=0.75,
     xlab="Values", ylab="Antithetic Values",
     main=paste("Correlation is", format(cor(g0, g1), digits=2)))
whuber
  • 281,159
  • 54
  • 637
  • 1,101
5

There is no answer to this question because the integral diverges and so numerically you won't get a reliable answer using simulation.

Here is a link to Wolfram to see that the integral diverges: http://www.wolframalpha.com/input/?i=integral_-infty^infty+integral_0^infity+si‌​n%28x%2By%29*e^%28x^2%2B4x-y%29+dx+dy

But since you insist that R says the integral evaluates to 18.58, here is some R code for calculating double integrals that says the contrary.

##############################################################################
###First Solution
############################################################################## 

myfun <- function(x,y) sin(x+y)*exp(x^2+4*x-y)
llim.x <- 0
ulim.x <- Inf

llim.y <- -Inf
ulim.y <- Inf

integrate(function(y) { 
   sapply(y, function(y) {
     integrate(function(x) myfun(x,y), llim.x, ulim.x)$value
   })
 }, llim.y, ulim.y)

##############################################################################
###Second Solution
############################################################################## 

library(pracma)
quad2d(myfun, 0, 1, -1, 1)
quad2d(myfun, 0, 10, -10, 10)
quad2d(myfun, 0, 100, -100, 100)
quad2d(myfun, 0, Inf, -Inf, Inf)

And so you see, in the second method, as you increase the limits to infinity, the solutions blows up to $\infty$.

  • sorry, I don't know how to send the code – albert Nov 25 '15 at 03:52
  • @albert, just edit your solutions and copy and paste it in. –  Nov 25 '15 at 04:03
  • f = function(x, y) { (sin(x+y))*exp(-(x)^2+4*(x)-(y)) } g = function(y) { z = length(y) for (i in 1:length(y)) z[i] = integrate(f, -Inf, Inf, y = y[i])$value z } print(integrate(g, 0, Inf)\$value) – albert Nov 25 '15 at 04:23
  • @albert, I don't understand your code. Your function $g$ takes in a parameter $y$ but what is $y$? Also, when I run the code you pasted it doesn't seem to run. –  Nov 25 '15 at 05:52
  • @albert and also, your `R` code has `exp(-(x)^2)` but your problem up above is $exp(x^2)$, so which one is it? (i.e., you are missing the negative sign) –  Nov 25 '15 at 05:53
  • naming function, for example fun – albert Nov 25 '15 at 13:20
  • @albert, something is still wrong with your code, but you also ignored my question about the negative sign. In either case, the integral diverges. –  Nov 25 '15 at 15:38
  • exp(-x^2)=exp(-(x)^2) != exp((-x)^2)=exp(x^2).... SOrry! I wrote it wrong. Is e^(-x^2+4x-y) – albert Nov 25 '15 at 15:53
  • 1
    @Albert, I understand that. But your original question did not have a negative sign. In fact you just edited it to have the negative sign. –  Nov 25 '15 at 15:56
  • I'm sorry, I did not realize I was wrong – albert Nov 25 '15 at 15:59
  • 1
    @albert, the integral still diverges. –  Nov 25 '15 at 16:03
  • +1 I have upvoted this answer because it addresses some crucial misconceptions in the question. However, it is clear that the original intent of the question is to see how one might use the method of antithetic variables to estimate an *improper* integral. It would be nice to see that illustrated here, rather than just using black-box code. – whuber Nov 27 '15 at 15:12