nifty.cl.library.special_distributions module#
- BetaOperator(domain, a, b, delta=0.01)[source]#
Transform a standard normal into a beta distribution.
- class GammaOperator(domain, alpha=None, beta=None, theta=None, mean=None, var=None, delta=0.01)[source]#
Bases:
OperatorTransform a standard normal into a gamma distribution.
The pdf of the gamma distribution is defined as follows:
\[\frac{1}{\Gamma(k)\theta^\alpha} x^{\alpha-1} \exp \left( -\frac{x}{\theta} \right)\]This transformation is implemented using linear interpolation to map a Gaussian distribution onto a gamma distribution.
- Parameters:
domain (Domain, tuple of Domain or DomainTuple) – The domain on which the field shall be defined. This is at the same time the domain and the target of the operator.
alpha (float) – The shape parameter of the gamma distribution.
beta (float or
nifty.cl.field.Field) – The rate parameter of the gamma distribution. Equals 1/theta.theta (float or
nifty.cl.field.Field) – The scale parameter of the gamma distribution. Equals 1/beta.mean (float) – Mean of the gamma distribution.
var (float) – Variance of the gamma distribution.
delta (float) – Distance between sampling points for linear interpolation.
Note
To specify the Gamma distribution, you can either specify (alpha, beta), (alpha, theta) or (mean, var).
- property alpha#
The value of the shape-parameter of the gamma distribution
- Type:
float
- apply(x)[source]#
Applies the operator to a Field, MultiField or Linearization.
- Parameters:
x (
nifty.cl.field.Field,nifty.cl.multi_field.MultiField,) – ornifty.cl.linearization.LinearizationInput on which the operator shall act. Needs to be defined ondomain. If x`is a :class:`nifty.cl.linearization.Linearization, apply returns a newnifty.cl.linearization.Linearizationcontining the result of the operator application as well as its Jacobian, evaluated at x.
- property beta#
The value of rate parameter of the gamma distribution
- Type:
float
- property mean#
The value of the mean of the gamma distribution.
- Type:
float
- property mode#
The value of the mode of the gamma distribution. Exists for alpha >= 1 or k >= 1.
- Type:
float
- property theta#
The value of scale parameter of the gamma distribution
- Type:
float
- property var#
The value of the variance of the gamma distribution.
- Type:
float
- class InverseGammaOperator(domain, alpha=None, q=None, delta=0.01, mode=None, mean=None)[source]#
Bases:
OperatorTransform a standard normal into an inverse gamma distribution.
The pdf of the inverse gamma distribution is defined as follows:
\[\frac{q^\alpha}{\Gamma(\alpha)}x^{-\alpha -1} \exp \left(-\frac{q}{x}\right)\]That means that for large x the pdf falls off like \(x^{(-\alpha -1)}\). The mean of the pdf is at \(q / (\alpha - 1)\) if \(\alpha > 1\). The mode is \(q / (\alpha + 1)\).
The operator can be initialized by setting either alpha and q or mode and mean. In accordance to the statements above the mean must be greater than the mode. Otherwise would get alpha < 0 and so no mean would be defined.
This transformation is implemented as a linear interpolation which maps a Gaussian onto an inverse gamma distribution.
- Parameters:
domain (Domain, tuple of Domain or DomainTuple) – The domain on which the field shall be defined. This is at the same time the domain and the target of the operator.
alpha (float) – The alpha-parameter of the inverse-gamma distribution.
q (float or
nifty.cl.field.Field) – The q-parameter of the inverse-gamma distribution.mode (float) – The mode of the inverse-gamma distribution.
mean (float) – The mean of the inverse-gamma distribution.
delta (float) – Distance between sampling points for linear interpolation.
- property alpha#
The value of the alpha-parameter of the inverse-gamma distribution
- Type:
float
- apply(x)[source]#
Applies the operator to a Field, MultiField or Linearization.
- Parameters:
x (
nifty.cl.field.Field,nifty.cl.multi_field.MultiField,) – ornifty.cl.linearization.LinearizationInput on which the operator shall act. Needs to be defined ondomain. If x`is a :class:`nifty.cl.linearization.Linearization, apply returns a newnifty.cl.linearization.Linearizationcontining the result of the operator application as well as its Jacobian, evaluated at x.
- property mean#
The value of the mean of the inverse-gamma distribution. Only existing for alpha > 1.
- Type:
float
- property mode#
The value of the mode of the inverse-gamma distribution
- Type:
float
- property q#
The value of q-parameters of the inverse-gamma distribution
- Type:
float
- property var#
The value of the variance of the inverse-gamma distribution. Only existing for alpha > 2.
- Type:
float
- class LaplaceOperator(domain, loc=0, scale=1)[source]#
Bases:
OperatorTransform a standard normal to a Laplace distribution.
- Parameters:
domain (Domain, tuple of Domain or DomainTuple) – The domain on which the field shall be defined. This is at the same time the domain and the target of the operator.
loc (float)
scale (float)
Note
If this operator is called on inputs stored on device, it will copy them to host, perform the operations with the CPU and copy back. This is done since Cupy does not support stats.laplace yet.
- apply(x)[source]#
Applies the operator to a Field, MultiField or Linearization.
- Parameters:
x (
nifty.cl.field.Field,nifty.cl.multi_field.MultiField,) – ornifty.cl.linearization.LinearizationInput on which the operator shall act. Needs to be defined ondomain. If x`is a :class:`nifty.cl.linearization.Linearization, apply returns a newnifty.cl.linearization.Linearizationcontining the result of the operator application as well as its Jacobian, evaluated at x.
- LogInverseGammaOperator(domain, alpha, q, delta=0.01)[source]#
Transform a standard normal into the log of an inverse gamma distribution.
See also
- class UniformOperator(domain, loc=0, scale=1)[source]#
Bases:
OperatorTransform a standard normal into a uniform distribution.
The uniform distribution’s support is
[loc, loc + scale].- Parameters:
domain (Domain, tuple of Domain or DomainTuple) – The domain on which the field shall be defined. This is at the same time the domain and the target of the operator.
loc (float)
scale (float)
- apply(x)[source]#
Applies the operator to a Field, MultiField or Linearization.
- Parameters:
x (
nifty.cl.field.Field,nifty.cl.multi_field.MultiField,) – ornifty.cl.linearization.LinearizationInput on which the operator shall act. Needs to be defined ondomain. If x`is a :class:`nifty.cl.linearization.Linearization, apply returns a newnifty.cl.linearization.Linearizationcontining the result of the operator application as well as its Jacobian, evaluated at x.