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

Cosmetics

parent 98e02dbf
......@@ -17,7 +17,7 @@
import numpy as np
from scipy.interpolate import CubicSpline
from scipy.stats import invgamma, norm, laplace
from scipy.stats import invgamma, laplace, norm
from .. import random
from ..domain_tuple import DomainTuple
......@@ -90,8 +90,7 @@ class _InterpolationOperator(Operator):
def InverseGammaOperator(domain, alpha, q, delta=1e-2):
"""Transforms a Gaussian with unit covariance and zero mean into an
inverse gamma distribution.
"""Transform a standard normal into an inverse gamma distribution.
The pdf of the inverse gamma distribution is defined as follows:
......@@ -126,9 +125,9 @@ def InverseGammaOperator(domain, alpha, q, delta=1e-2):
class UniformOperator(Operator):
"""
Transforms a Gaussian with unit covariance and zero mean into a uniform
distribution. The uniform distribution's support is ``[loc, loc + scale]``.
"""Transform a standard normal into a uniform distribution.
The uniform distribution's support is ``[loc, loc + scale]``.
Parameters
----------
......@@ -159,10 +158,9 @@ class UniformOperator(Operator):
res = norm._ppf(field.val/self._scale - self._loc)
return Field(field.domain, res)
class LaplaceOperator(Operator):
"""
Transforms a Gaussian with uni covariance and zero mean to a Laplace distribution
via a uniform distribution.
"""Transform a standard normal to a Laplace distribution.
Parameters
-----------
......@@ -170,6 +168,7 @@ class LaplaceOperator(Operator):
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
"""
def __init__(self, domain, loc=0, scale=1):
......@@ -184,13 +183,11 @@ class LaplaceOperator(Operator):
res = Field(self._target, laplace.ppf(norm._cdf(xval), self._loc, self._scale))
if not lin:
return res
jac = makeOp(Field(self.domain, self._jac_func(norm._cdf(xval))*norm._pdf(xval)))
y = norm._cdf(xval)
y = self._scale * np.where(y > 0.5, 1/(1-y), 1/y)
jac = makeOp(Field(self.domain, y*norm._pdf(xval)))
return x.new(res, jac)
def inverse(self, x):
res = laplace._cdf(x.val)
return Field(x.domain, res)
def _jac_func(self, x):
res = self._scale*np.where(x > 0.5, (1/(1-x)), (1/x))
return res
Supports Markdown
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