Commit ef420611 authored by Reimar H Leike's avatar Reimar H Leike
Browse files

added a studentTOperator analogously to the InverseGammaOperator. Added tests...

added a studentTOperator analogously to the InverseGammaOperator. Added tests and raised the jacobian tolerance for both Operators. Fixed bugs from previious commit
parent f227a461
......@@ -74,6 +74,7 @@ from .sugar import *
from .plot import Plot
from .library.inverse_gamma_operator import InverseGammaOperator
from .library.studentt_operator import StudentTOperator
from .library.los_response import LOSResponse
from .library.dynamic_operator import (dynamic_operator,
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <>.
# Copyright(C) 2013-2019 Max-Planck-Society
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import numpy as np
from scipy.stats import t, norm
from ..operators.interpolating_operator import InterpolatingOperator
def StudentTOperator(domain, alpha, q, bounds=(-8.2,8.2), delta=0.001):
"""Transforms a Gaussian into a Student T distributed quantity
The pdf of the Student T for :math:`q=1` is defined as follows:
.. math::
{\\sqrt{\\alpha \\pi}\\Gamma(\\frac{\\alpha}{2})}
The parameter :math:`q` is just a scaling parameter
The mean and mode of the distribution is at 0
The variance is "math:`\\frac{q^2\\alpha}{\\alpha-2}` for :math:`\\alpha>2`
This transformation is implemented as a linear interpolation which maps a
Gaussian onto a Student T distribution
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 degree of freedom parameter of the Student T distribution
q : float
The scale parameter of the Student T distribution
delta : float
distance between sampling points for linear interpolation.
func = lambda x: t.ppf(norm.cdf(x), alpha)
return InterpolatingOperator(domain, func, bounds, delta)
......@@ -96,7 +96,9 @@ def testPointModel(space, seed):
q = 0.73
model = ift.InverseGammaOperator(space, alpha, q)
# FIXME All those cdfs and ppfs are not very accurate
ift.extra.check_jacobian_consistency(model, pos, tol=1e-2, ntries=20)
ift.extra.check_jacobian_consistency(model, pos, tol=1e-5, ntries=20)
model = ift.StudentTOperator(space, alpha, q)
ift.extra.check_jacobian_consistency(model, pos, tol=1e-5, ntries=20)
@pmp('target', [
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