Commit c0d4c04c authored by Philipp Arras's avatar Philipp Arras
Browse files

Add Laplace distribution

parent 9520f5af
Pipeline #92460 passed with stages
in 11 minutes and 7 seconds
......@@ -77,7 +77,8 @@ from .sugar import *
from .plot import Plot
from .library.special_distributions import InverseGammaOperator, UniformOperator
from .library.special_distributions import (InverseGammaOperator, UniformOperator,
LaplaceOperator)
from .library.los_response import LOSResponse
from .library.dynamic_operator import (dynamic_operator,
dynamic_lightcone_operator)
......
......@@ -17,7 +17,7 @@
import numpy as np
from scipy.interpolate import CubicSpline
from scipy.stats import invgamma, norm
from scipy.stats import invgamma, norm, laplace
from .. import random
from ..domain_tuple import DomainTuple
......@@ -158,3 +158,29 @@ class UniformOperator(Operator):
def inverse(self, field):
res = norm._ppf(field.val/self._scale - self._loc)
return Field(field.domain, res)
def LaplaceOperator(domain, alpha, delta=1e-2):
"""Transforms a Gaussian with unit covariance and zero mean into a
Laplacian distribution.
The pdf of the laplace distribution is defined as follows:
.. math::
\\frac{\\alpha}{2} \\exp \\left(-\\alpha |x| \\right)
This transformation is implemented as a spline interpolation which maps a
Gaussian onto 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.
alpha : float
The alpha-parameter of the Laplace distribution.
delta : float
Distance between sampling points for spline interpolation.
"""
return _InterpolationOperator(domain, lambda x: laplace.ppf(norm._cdf(x), float(alpha)),
-8.2, 8.2, delta)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment