glearn.priors.Cauchy#

class glearn.priors.Cauchy(median=0.0, scale=1.0, half=False)#

Cauchy distribution.

Note

For the methods of this class, see the base class glearn.priors.Prior.

Parameters:
medianfloat or array_like[float], default=0.0

The median \(\theta_0\) of Cauchy distribution. If an array \(\boldsymbol{\theta}_0 = (\theta_{01}, \dots, \theta_{0p})\) is given, the prior is assumed to be \(p\) independent Cauchy distributions each with median \(\theta_{i0}\).

stdfloat or array_like[float], default=1.0

The scale parameter \(\gamma\) of Cauchy distribution. If an array \(\boldsymbol{\gamma} = (\gamma_1, \dots, \gamma_p)\) is given, the prior is assumed to be \(p\) independent Cauchy distributions each with scale \(\gamma_i\).

halfbool, default=False

If True, the prior is the half-Cauchy distribution.

Notes

Single Hyperparameter:

The Cauchy distribution with median \(\theta_0\) and scale \(\gamma\) is defined by the probability density function

\[p(\theta \vert \theta_0, \gamma) = \frac{1}{\pi \gamma} \frac{1}{1 + \left( \frac{\theta - \theta_0}{\gamma} \right)^2}.\]

If half is True, the prior is the half-normal distribution

\[p(\theta \vert \theta_0, \gamma) = \frac{2}{\pi \gamma} \frac{1}{1 + \left( \frac{\theta - \theta_0}{\gamma} \right)^2}.\]

Multiple Hyperparameters:

If an array of the hyperparameters are given, namely \(\boldsymbol{\theta} = (\theta_1, \dots, \theta_p)\), then the prior is the product of independent priors

\[p(\boldsymbol{\theta}) = p(\theta_1) \dots p(\theta_p).\]

In this case, if the input arguments median and scale are given as the arrays \(\boldsymbol{\theta}_0 = (\theta_{01}, \dots, \theta_{0p})\) and \(\boldsymbol{\gamma} = (\gamma_1, \dots, \gamma_p)\), each prior \(p(\theta_i)\) is defined as the Cauchy distribution with median \(\theta_{0i}\) and scale \(\gamma_i\). In contrary, if median and scale are given as the scalars \(\theta_0\) and \(\gamma\), then all priors \(p(\theta_i)\) are defined as the Cauchy distribution with median \(\theta_0\) and scale \(\gamma\).

Examples

Create Prior Objects:

Create the Cauchy distribution with median \(\theta_0 = 1\) and scale \(\gamma=2\).

>>> from glearn import priors
>>> prior = priors.Cauchy(1, 2)

>>> # Evaluate PDF function at multiple locations
>>> t = [0, 0.5, 1]
>>> prior.pdf(t)
array([0.12732395, 0.14979289, 0.15915494])

>>> # Evaluate the Jacobian of the PDF
>>> prior.pdf_jacobian(t)
array([-0.        , -0.03524539, -0.07957747])

>>> # Evaluate the Hessian of the PDF
>>> prior.pdf_hessian(t)
array([[-0.05092958,  0.        ,  0.        ],
       [ 0.        , -0.05390471,  0.        ],
       [ 0.        ,  0.        ,  0.        ]])

>>> # Evaluate the log-PDF
>>> prior.log_pdf(t)
8.651043137341349

>>> # Evaluate the Jacobian of the log-PDF
>>> prior.log_pdf_jacobian(t)
array([-1.15129255, -5.30828143, -5.41784728])

>>> # Evaluate the Hessian of the log-PDF
>>> prior.log_pdf_hessian(t)
array([[-3.97642358,  0.        ,  0.        ],
       [ 0.        ,  3.73231234,  0.        ],
       [ 0.        ,  0.        ,  4.40296037]])

>>> # Plot the distribution and its first and second derivative
>>> prior.plot()
../_images/prior_cauchy.png

Where to Use the Prior object:

Define a covariance model (see glearn.Covariance) where its scale parameter is a prior function.

>>> # Generate a set of sample points
>>> from glearn.sample_data import generate_points
>>> points = generate_points(num_points=50)

>>> # Create covariance object of the points with the above kernel
>>> from glearn import covariance
>>> cov = glearn.Covariance(points, kernel=kernel, scale=prior)
Attributes:
medianfloat or array_like[float], default=0

Median \(\theta_0\) of the distribution

scalefloat or array_like[float], default=0

Scale parameter \(\gamma\) of the distribution

Methods

suggest_hyperparam([positive])

Find an initial guess for the hyperparameters based on the peaks of the prior distribution.

pdf(x)

Probability density function of the prior distribution.

pdf_jacobian(x)

Jacobian of the probability density function of the prior distribution.

pdf_hessian(x)

Hessian of the probability density function of the prior distribution.