LibRan  0.1
Pseudo-random number distribution generator
Functions
LRcauchy.c File Reference

The Cauchy (or Lorentz) distribution centered on m and width given by 2s. More...

#include <math.h>
#include "libran.h"
Include dependency graph for LRcauchy.c:

Go to the source code of this file.

Functions

double LRd_cauchy_RAN (LR_obj *o)
 LRd_cauchy_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the inversion method on the CDF(x). Default values: peak m = 0, half width s = 1. More...
 
double LRd_cauchymar_RAN (LR_obj *o)
 LRd_cauchymar_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the polar method and the Marsagalia method and acceptance/rejection for generating a Gaussian/Normal variate. Default values: peak m = 0, half width s = 1. More...
 
double LRd_cauchy_PDF (LR_obj *o, double x)
 LRd_cauchy_PDF(LR_obj *o, double x) - double Cauchy/Lorentz probablity distribution function. More...
 
double LRd_cauchy_CDF (LR_obj *o, double x)
 LRd_cauchy_CDF(LR_obj *o, double x) - double Cauchy/Lorentz cumulative distribution function. More...
 
float LRf_cauchy_RAN (LR_obj *o)
 LRf_cauchy_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the inversion method. Default values: peak m = 0, half width s = 1. More...
 
float LRf_cauchymar_RAN (LR_obj *o)
 LRf_cauchymar_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the polar method and the Marsagalia method and acceptance/rejection for generating a Gaussian/Normal variate. Default values: peak m = 0, half width s = 1. More...
 
float LRf_cauchy_PDF (LR_obj *o, float x)
 LRf_cauchy_PDF(LR_obj *o, float x) - float Cauchy/Lorentz probablity distribution function. More...
 
float LRf_cauchy_CDF (LR_obj *o, float x)
 LRf_cauchy_CDF(LR_obj *o, float x) - float Cauchy/Lorentz cumulative distribution function. More...
 

Detailed Description

The Cauchy (or Lorentz) distribution centered on m and width given by 2s.

The pseudo-random numbers are distributed from a Cauchy or Lorentz distribution. It's a pathological distribution where the mean and variance are undefined, but the distribution has a clear peak and width (given by m and 2s respectively).

\begin{eqnarray*} \mbox{PDF}(x) &= \frac{1}{ \pi s \left[1 + \left(\frac{x-m}{s} \right)^2 \right]} \\ &= \frac{1}{ \pi s }\left[\frac{s^2}{(x-m)^2 + s^2}\right] \\ \mbox{CDF}(x) &= \frac{1}{\pi}\arctan \left(\frac{x-m}{s} \right) + \frac{ 1}{ 2} \end{eqnarray*}

The default is m = 0, s = 1; which is called the standard Cauchy distribution.

CauchyLorentzDistribution.png
The Cauchy-Lorentz distributed random variates can be generated in a couple of ways. The first and most direct way comes using the inverse of the $ \mbox{CDF}(x) $ function, which is simple enough to have an exact analytic form. However, the computational complexity may cause it to be slower than the second method.

The second method uses the polar method, the Marsagalia method, and acceptance/rejection for generating a Gaussian/Normal variate - the ratio of the two independent variates gives the Cauchy-Lorentz distribution. However, it relies on acceptance/rejection to generate random variates confined to the unit circle centered on the origin with radius 1. This gives an acceptance ratio to be $\frac{\pi}{4} \approx 78.5\% $, but the only arithmetic operations, however, are couple of multiplications and a single division. This simplicity may be sufficient to overcome the time to generate rejected samples and the overall method may be competative in comparison to the first method.

Default values: peak m = 0, half width s = 1

Definition in file LRcauchy.c.

Function Documentation

◆ LRd_cauchy_CDF()

double LRd_cauchy_CDF ( LR_obj o,
double  x 
)

LRd_cauchy_CDF(LR_obj *o, double x) - double Cauchy/Lorentz cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
double CDF at x

Definition at line 117 of file LRcauchy.c.

◆ LRd_cauchy_PDF()

double LRd_cauchy_PDF ( LR_obj o,
double  x 
)

LRd_cauchy_PDF(LR_obj *o, double x) - double Cauchy/Lorentz probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
double PDF at x

Definition at line 103 of file LRcauchy.c.

◆ LRd_cauchy_RAN()

double LRd_cauchy_RAN ( LR_obj o)

LRd_cauchy_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the inversion method on the CDF(x). Default values: peak m = 0, half width s = 1.

Parameters
oLR_obj object
Returns
double

Definition at line 71 of file LRcauchy.c.

◆ LRd_cauchymar_RAN()

double LRd_cauchymar_RAN ( LR_obj o)

LRd_cauchymar_RAN(LR_obj *o) - double random Cauchy/Lorentz distribution using the polar method and the Marsagalia method and acceptance/rejection for generating a Gaussian/Normal variate. Default values: peak m = 0, half width s = 1.

Parameters
oLR_obj object
Returns
double

Definition at line 84 of file LRcauchy.c.

◆ LRf_cauchy_CDF()

float LRf_cauchy_CDF ( LR_obj o,
float  x 
)

LRf_cauchy_CDF(LR_obj *o, float x) - float Cauchy/Lorentz cumulative distribution function.

Parameters
oLR_obj object
xvalue
Returns
float CDF at x

Definition at line 180 of file LRcauchy.c.

◆ LRf_cauchy_PDF()

float LRf_cauchy_PDF ( LR_obj o,
float  x 
)

LRf_cauchy_PDF(LR_obj *o, float x) - float Cauchy/Lorentz probablity distribution function.

Parameters
oLR_obj object
xvalue
Returns
float PDF at x

Definition at line 166 of file LRcauchy.c.

◆ LRf_cauchy_RAN()

float LRf_cauchy_RAN ( LR_obj o)

LRf_cauchy_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the inversion method. Default values: peak m = 0, half width s = 1.

Parameters
oLR_obj object
Returns
float

Definition at line 134 of file LRcauchy.c.

◆ LRf_cauchymar_RAN()

float LRf_cauchymar_RAN ( LR_obj o)

LRf_cauchymar_RAN(LR_obj *o) - float random Cauchy/Lorentz distribution using the polar method and the Marsagalia method and acceptance/rejection for generating a Gaussian/Normal variate. Default values: peak m = 0, half width s = 1.

Parameters
oLR_obj object
Returns
float

Definition at line 147 of file LRcauchy.c.