You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maximum likelihood estimation (MLE) of the location parameter of the Cauchy (Lorentzian) distribution.
Usage
All functionality is contained inside cauchy.py. Example usage:
fromcauchyimportcauchy_sample, cauchy_mlealpha=2# location parameterbeta=1# scale parameter# generate random sample of size 10000 from Cauchy distributionx=cauchy_sample(10000, alpha, beta)
# Maximum likelihood estimation of location parameteralpha_mle=cauchy_mle(x=x, # samplebeta=beta, # known scale parameterstart=1, # initial guess (if None, we use median of x)tol=1e-6, # tolerance for convergencemax_iter=1000) # maximum number of iterations
We typically obtain the maximum likelihood estimate by setting $l'(\hat{\alpha}) = 0$, but in the case of the Cauchy distribution, there is no closed form expression for $\hat{\alpha}$, thus we estimate it using the Newton-Raphson method. We pick an initial guess, $\alpha_0$, then iterate the following expression until convergence:
To sample from $\text{Cauchy}(x; \alpha, \beta)$, we can sample $\theta \in (-\frac{\pi}{2}, \frac{\pi}{2})$ uniformly, and transform it using the equation $x = \alpha + \beta \tan{\theta}$.
Proof: Let $x = \alpha + \beta \tan{\theta}$, where $\theta$ is a uniformly distributed random variable over $(-\frac{\pi}{2}, \frac{\pi}{2})$. This equation for $x$ is monotonically increasing over $\theta \in (-\frac{\pi}{2}, \frac{\pi}{2})$, hence the PDF of $x$ satisfies $f(x)dx = u(\theta)d\theta$, where $u(\theta)$ is the PDF of $\theta$, given by