Commit 69cf17db authored by Philipp Arras's avatar Philipp Arras
Browse files

Add test

parent f430d35b
Pipeline #70451 passed with stages
in 15 minutes and 42 seconds
......@@ -81,6 +81,9 @@ def InverseGammaOperator(domain, alpha, q, delta=0.001):
delta : float
distance between sampling points for linear interpolation.
"""
return _InterpolationOperator(domain,
lambda x: invgamma.ppf(norm.cdf(x), float(alpha)),
-8.2, 8.2, delta, np.log, np.exp).scale(q)
op = _InterpolationOperator(domain,
lambda x: invgamma.ppf(norm.cdf(x), float(alpha)),
-8.2, 8.2, delta, np.log, np.exp)
if np.isscalar(q):
return op.scale(q)
return makeOp(q) @ op
......@@ -15,6 +15,7 @@
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
import numpy as np
import pytest
from numpy.testing import assert_allclose
from scipy.stats import invgamma, norm
......@@ -35,8 +36,12 @@ def testInverseGammaAccuracy(space, seed):
S = ift.ScalingOperator(space, 1.)
pos = S.draw_sample()
alpha = 1.5
q = 0.73
op = ift.InverseGammaOperator(space, alpha, q)
arr1 = op(pos).val
arr0 = q*invgamma.ppf(norm.cdf(pos.val), alpha)
assert_allclose(arr0, arr1)
qs = [0.73, pos.exp().val]
for q in qs:
qfld = q
if not np.isscalar(q):
qfld = ift.makeField(space, q)
op = ift.InverseGammaOperator(space, alpha, qfld)
arr1 = op(pos).val
arr0 = invgamma.ppf(norm.cdf(pos.val), alpha, scale=q)
assert_allclose(arr0, arr1)
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