Commit 77d9d3e0 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'pa' into 'NIFTy_7'

Treat scaling correctly

See merge request !616
parents 4dca30b7 5beafe79
Pipeline #98215 passed with stages
in 24 minutes and 52 seconds
......@@ -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):
......
......@@ -479,7 +479,7 @@ def exec_time(obj, want_metric=True):
res = obj(lin)
logger.info('Operator call with linearization: {}'.format(time() - t0))
if isinstance(obj, EnergyOperator):
if obj.target is DomainTuple.scalar_domain():
t0 = time()
res.gradient
logger.info('Gradient evaluation: {}'.format(time() - t0))
......
......@@ -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)
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