Segment 11 Sanmit Narvekar

From Computational Statistics Course Wiki
Jump to navigation Jump to search

Segment 11

To Calculate

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

Given the Cauchy distribution:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle p(x) = \frac{1}{\pi \sigma} \left(1 + \left[\frac{x - \mu}{\sigma} \right]^2 \right)^{-1}}

First we calculate the CDF Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle C } , by integrating from negative infinity to Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c} .

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle C(c) = \int_{-\infty}^c p(x) dx}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle = \int_{-\infty}^c \frac{1}{\pi \sigma} \left(1 + \left[\frac{x - \mu}{\sigma} \right]^2 \right)^{-1} dx}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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 Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle u = \frac{x - \mu}{\sigma}} and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle du = \frac{1}{\sigma} dx} , and make the appropriate changes to the limits of integration.

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle =\frac{1}{\pi} tan^{-1}(u) \Big|_{-\infty}^{\frac{c - \mu}{\sigma}}}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle =\frac{1}{\pi} \left( tan^{-1} \left( \frac{c - \mu}{\sigma} \right) + \frac{\pi}{2} \right)}

And so:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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):

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c = \frac{1}{\pi} tan^{-1} \left( \frac{C^{-1} - \mu}{\sigma} \right) + \frac{1}{2} }

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \Rightarrow \tan (\pi (c - \frac{1}{2})) = \frac{C^{-1} - \mu}{\sigma}}

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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:

SanmitSeg11 cauchy.png

To Think About

1. Suppose you want a function that returns deviates for StudentFailed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\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)?


2. Explain the three inequality tests in the "while" statement in Leva's algorithm (slide 7) and why they are hooked together with logical operators in the way shown.


Comments