# Cauchy¶

class paddle.distribution. Cauchy ( loc, scale, name=None ) [source]

Cauchy distribution is also called Cauchy–Lorentz distribution. It is a continuous probability distribution named after Augustin-Louis Cauchy and Hendrik Lorentz. It has a very wide range of applications in natural sciences.

The Cauchy distribution has the probability density function (PDF):

${ f(x; loc, scale) = \frac{1}{\pi scale \left[1 + \left(\frac{x - loc}{ scale}\right)^2\right]} = { 1 \over \pi } \left[ { scale \over (x - loc)^2 + scale^2 } \right], }$
Parameters
• loc (float|Tensor) – Location of the peak of the distribution. The data type is float32 or float64.

• scale (float|Tensor) – The half-width at half-maximum (HWHM). The data type is float32 or float64. Must be positive values.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
>>> print(rv.entropy())
2.71334577)

>>> # init Cauchy with N-Dim tensor
>>> print(rv.entropy())
[2.53102422, 3.22417140])

property mean

Mean of Cauchy distribution.

property variance

Variance of Cauchy distribution.

property stddev

Standard Deviation of Cauchy distribution.

sample ( shape, name=None )

Sample from Cauchy distribution.

Note

Parameters
• shape (Sequence[int]) – Sample shape.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Sampled data with shape sample_shape + batch_shape + event_shape.

Return type

Tensor

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
>>> print(rv.sample([10]).shape)
[10]

>>> # init Cauchy with 0-Dim tensor
>>> print(rv.sample([10]).shape)
[10]

>>> # init Cauchy with N-Dim tensor
>>> print(rv.sample([10]).shape)
[10, 2]

>>> # sample 2-Dim data
>>> rv = Cauchy(loc=0.1, scale=1.2)
>>> print(rv.sample([10, 2]).shape)
[10, 2]

>>> print(rv.sample([10, 2]).shape)
[10, 2, 2]

rsample ( shape, name=None )

Sample from Cauchy distribution (reparameterized).

Parameters
• shape (Sequence[int]) – Sample shape.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Sampled data with shape sample_shape + batch_shape + event_shape.

Return type

Tensor

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
>>> print(rv.rsample([10]).shape)
[10]

>>> # init Cauchy with 0-Dim tensor
>>> print(rv.rsample([10]).shape)
[10]

>>> # init Cauchy with N-Dim tensor
>>> print(rv.rsample([10]).shape)
[10, 2]

>>> # sample 2-Dim data
>>> rv = Cauchy(loc=0.1, scale=1.2)
>>> print(rv.rsample([10, 2]).shape)
[10, 2]

>>> print(rv.rsample([10, 2]).shape)
[10, 2, 2]

prob ( value )

Probability density function(PDF) evaluated at value.

${ f(x; loc, scale) = \frac{1}{\pi scale \left[1 + \left(\frac{x - loc}{ scale}\right)^2\right]} = { 1 \over \pi } \left[ { scale \over (x - loc)^2 + scale^2 } \right], }$
Parameters

value (Tensor) – Value to be evaluated.

Returns

PDF evaluated at value.

Return type

Tensor

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
0.11234467)

>>> rv = Cauchy(loc=0.1, scale=1.2)
[0.11234467, 0.01444674])

>>> # init Cauchy with N-Dim tensor
[0.10753712, 0.02195240])

>>> # init Cauchy with N-Dim tensor with broadcast
[0.10753712, 0.02195240])

log_prob ( value )

Log of probability densitiy function.

Parameters

value (Tensor) – Value to be evaluated.

Returns

Log of probability densitiy evaluated at value.

Return type

Tensor

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
-2.18618369)

>>> rv = Cauchy(loc=0.1, scale=1.2)
[-2.18618369, -4.23728657])

>>> # init Cauchy with N-Dim tensor
[-2.22991920, -3.81887865])

>>> # init Cauchy with N-Dim tensor with broadcast
[-2.22991920, -3.81887865])

cdf ( value )

Cumulative distribution function(CDF) evaluated at value.

${ \frac{1}{\pi} \arctan\left(\frac{x-loc}{ scale}\right)+\frac{1}{2}\! }$
Parameters

value (Tensor) – Value to be evaluated.

Returns

CDF evaluated at value.

Return type

Tensor

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
0.77443725)

>>> rv = Cauchy(loc=0.1, scale=1.2)
[0.77443725, 0.92502367])

>>> # init Cauchy with N-Dim tensor
[0.80256844, 0.87888104])

>>> # init Cauchy with N-Dim tensor with broadcast
[0.80256844, 0.87888104])

property batch_shape

Returns batch shape of distribution

Returns

batch shape

Return type

Sequence[int]

entropy ( )

Entropy of Cauchy distribution.

${ \log(4\pi scale)\! }$
Returns

Entropy of distribution.

Return type

Tensor

Examples

>>> import paddle

>>> # init Cauchy with float
>>> rv = Cauchy(loc=0.1, scale=1.2)
>>> print(rv.entropy())
2.71334577)

>>> # init Cauchy with N-Dim tensor
>>> print(rv.entropy())
[2.53102422, 3.22417140])

property event_shape

Returns event shape of distribution

Returns

event shape

Return type

Sequence[int]

probs ( value )

Probability density/mass function.

Note

This method will be deprecated in the future, please use prob instead.

kl_divergence ( other ) [source]

The KL-divergence between two Cauchy distributions.

Note

[1] Frédéric Chyzak, Frank Nielsen, A closed-form formula for the Kullback-Leibler divergence between Cauchy distributions, 2019

Parameters

other (Cauchy) – instance of Cauchy.

Returns

kl-divergence between two Cauchy distributions.

Return type

Tensor

Examples

>>> import paddle