Commit 5beafe79 authored by Philipp Arras's avatar Philipp Arras
Browse files

LogInverseGammaOperator: treat scaling correctly

parent 413e8ee5
......@@ -23,6 +23,7 @@ from .. import random
from ..domain_tuple import DomainTuple
from ..domains.unstructured_domain import UnstructuredDomain
from ..field import Field
from ..operators.adder import Adder
from ..operators.operator import Operator
from ..sugar import makeOp
......@@ -133,9 +134,8 @@ def LogInverseGammaOperator(domain, alpha, q, delta=1e-2):
"""
op = _InterpolationOperator(domain, lambda x: np.log(invgamma.ppf(norm._cdf(x), float(alpha))),
-8.2, 8.2, delta)
if np.isscalar(q):
return op.scale(q)
return makeOp(q) @ op
q = np.log(q) if np.isscalar(q) else q.log()
return Adder(q, domain=op.target) @ op
class UniformOperator(Operator):
......
......@@ -11,7 +11,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2019 Max-Planck-Society
# Copyright(C) 2013-2021 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
......@@ -41,6 +41,9 @@ def testInterpolationAccuracy(space, seed):
if not np.isscalar(q):
qfld = ift.makeField(space, q)
op = ift.InverseGammaOperator(space, alpha, qfld)
op1 = ift.LogInverseGammaOperator(space, alpha, qfld).exp()
arr1 = op(pos).val
arr2 = op1(pos).val
arr0 = invgamma.ppf(norm.cdf(pos.val), alpha, scale=q)
assert_allclose(arr0, arr1)
assert_allclose(arr0, arr2)
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