# Segment 11 Sanmit Narvekar

## Segment 11

#### To Calculate

1. For the Cauchy distribution (Segment 8, Slide 3), find the inverse function of the CDF.

Given the Cauchy distribution:

$\displaystyle p(x) = \frac{1}{\pi \sigma} \left(1 + \left[\frac{x - \mu}{\sigma} \right]^2 \right)^{-1}$

First we calculate the CDF $\displaystyle C$ , by integrating from negative infinity to $\displaystyle c$ .

$\displaystyle C(c) = \int_{-\infty}^c p(x) dx$

$\displaystyle = \int_{-\infty}^c \frac{1}{\pi \sigma} \left(1 + \left[\frac{x - \mu}{\sigma} \right]^2 \right)^{-1} dx$

$\displaystyle =\frac{1}{\pi \sigma} \int_{-\infty}^c \frac{1}{\left(1 + \left[\frac{x - \mu}{\sigma} \right]^2 \right)} dx$

Now we make the substitution $\displaystyle u = \frac{x - \mu}{\sigma}$ and $\displaystyle du = \frac{1}{\sigma} dx$ , and make the appropriate changes to the limits of integration.

$\displaystyle =\frac{1}{\pi \sigma} (\sigma) \int_{-\infty}^{\frac{c - \mu}{\sigma}} \frac{1}{\left(1 + u^2 \right)} du$

From a table of integrals, it can be seen that the integral evaluates to arctan:

$\displaystyle =\frac{1}{\pi} tan^{-1}(u) \Big|_{-\infty}^{\frac{c - \mu}{\sigma}}$

$\displaystyle =\frac{1}{\pi} \left( tan^{-1} \left( \frac{c - \mu}{\sigma} \right) + \frac{\pi}{2} \right)$

And so:

$\displaystyle C(c) = \frac{1}{\pi} tan^{-1} \left( \frac{c - \mu}{\sigma} \right) + \frac{1}{2}$

To find the inverse, we swap the places of C(c) and c, and solve for C(c):

$\displaystyle c = \frac{1}{\pi} tan^{-1} \left( \frac{C^{-1} - \mu}{\sigma} \right) + \frac{1}{2}$

$\displaystyle \Rightarrow \tan (\pi (c - \frac{1}{2})) = \frac{C^{-1} - \mu}{\sigma}$

$\displaystyle \Rightarrow C^{-1}(c) = \mu + \sigma \tan \left( c \pi - \frac{\pi}{2}\right)$

2. In your favorite programming language, write a function that returns independent Cauchy deviates.

   import random
import math
import numpy
from matplotlib import pyplot

   def randCauchy(mu, sigma):
return (mu + (sigma * math.tan((random.random() * math.pi) - (math.pi / 2.0))))

   def main():
nPoints = 1000000
mu = 0
sigma = 1

       x = numpy.zeros(nPoints)
for i in range(nPoints):
x[i] = randCauchy(mu, sigma)

       pyplot.hist(x, bins=100, range=(-10,10), normed=True)
pyplot.title('Cauchy distribution\n (mean = %3.2f, variance = %3.2f)' % (mu, sigma))
pyplot.xlabel('x')
pyplot.ylabel('p(x)')
pyplot.show()

if __name__=="__main__":
main()


And the corresponding graph:

1. Suppose you want a function that returns deviates for Student$\displaystyle (\nu)$ . Could you use the Cauchy pdf (or some scaling of it) as a bounding function in a rejection method? How efficient is this (i.e., what fraction of the time does it reject)?