Commit 7426a730 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

cleanups

parent 3f00aed2
......@@ -81,8 +81,6 @@ from .library.gaussian_energy import GaussianEnergy
from .library.los_response import LOSResponse
from .library.point_sources import PointSources
from .library.poissonian_energy import PoissonianEnergy
from .library.wiener_filter_curvature import WienerFilterCurvature
from .library.wiener_filter_energy import WienerFilterEnergy
from .library.correlated_fields import (make_correlated_field,
make_mf_correlated_field)
from .library.bernoulli_energy import BernoulliEnergy
......
......@@ -70,16 +70,6 @@ class PointSources(Model):
foo = invgamma.ppf(norm.cdf(field.local_data), alpha, scale=q)
return Field.from_local_data(field.domain, foo)
# MR FIXME: is this function needed?
@staticmethod
def IG_prime(field, alpha, q):
inner = norm.pdf(field.local_data)
outer = invgamma.pdf(invgamma.ppf(norm.cdf(field.local_data), alpha,
scale=q), alpha, scale=q)
# # FIXME
# outer = np.clip(outer, 1e-20, None)
return Field.from_local_data(field.domain, inner/outer)
# MR FIXME: why does this take an np.ndarray instead of a Field?
@staticmethod
def inverseIG(u, alpha, q):
......
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import absolute_import, division, print_function
from ..compat import *
from ..operators.sandwich_operator import SandwichOperator
from ..operators.inversion_enabler import InversionEnabler
from ..operators.sampling_enabler import SamplingEnabler
def WienerFilterCurvature(R, N, S, iteration_controller=None,
iteration_controller_sampling=None):
"""The curvature of the WienerFilterEnergy.
This operator implements the second derivative of the
WienerFilterEnergy used in some minimization algorithms or
for error estimates of the posterior maps. It is the
inverse of the propagator operator.
Parameters
----------
R : LinearOperator
The response operator of the Wiener filter measurement.
N : EndomorphicOperator
The noise covariance.
S : DiagonalOperator
The prior signal covariance
iteration_controller : IterationController
The iteration controller to use during numerical inversion via
ConjugateGradient.
iteration_controller_sampling : IterationController
The iteration controller to use for sampling.
"""
M = SandwichOperator.make(R, N.inverse)
if iteration_controller_sampling is not None:
op = SamplingEnabler(M, S.inverse, iteration_controller_sampling,
S.inverse)
else:
op = M + S.inverse
return InversionEnabler(op, iteration_controller, S.inverse)
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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 <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.
from __future__ import absolute_import, division, print_function
from ..compat import *
from ..minimization.quadratic_energy import QuadraticEnergy
from .wiener_filter_curvature import WienerFilterCurvature
def WienerFilterEnergy(position, d, R, N, S, iteration_controller=None,
iteration_controller_sampling=None):
"""The Energy for the Wiener filter.
It covers the case of linear measurement with
Gaussian noise and Gaussian signal prior with known covariance.
Parameters
----------
position : Field
The current map in harmonic space.
d : Field
the data
R : LinearOperator
The response operator, description of the measurement process. It needs
to map from harmonic signal space to data space.
N : EndomorphicOperator
The noise covariance in data space.
S : EndomorphicOperator
The prior signal covariance in harmonic space.
inverter : Minimizer, optional
the minimization strategy to use for operator inversion
If None, the energy object will not support curvature computation.
sampling_inverter : Minimizer, optional
The minimizer to use during numerical sampling
if None, it is not possible to draw inverse samples
default: None
"""
op = WienerFilterCurvature(R, N, S, iteration_controller,
iteration_controller_sampling)
vec = R.adjoint_times(N.inverse_times(d))
return QuadraticEnergy(position, op, vec)
......@@ -28,40 +28,6 @@ def _flat_PS(k):
class Energy_Tests(unittest.TestCase):
@expand(product([ift.GLSpace(15),
ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)],
[4, 78, 23]))
def testLinearMap(self, space, seed):
np.random.seed(seed)
dim = len(space.shape)
hspace = space.get_default_codomain()
ht = ift.HarmonicTransformOperator(hspace, target=space)
binbounds = ift.PowerSpace.useful_binbounds(hspace, logarithmic=False)
pspace = ift.PowerSpace(hspace, binbounds=binbounds)
Dist = ift.PowerDistributor(target=hspace, power_space=pspace)
xi0 = ift.Field.from_random(domain=hspace, random_type='normal')
def pspec(k): return 1 / (1 + k**2)**dim
pspec = ift.PS_field(pspace, pspec)
A = Dist(ift.sqrt(pspec))
n = ift.Field.from_random(domain=space, random_type='normal')
s0 = xi0 * A
Instrument = ift.ScalingOperator(10., space)
R = Instrument * ht
N = ift.ScalingOperator(1., space)
d = R(s0) + n
IC = ift.GradientNormController(
iteration_limit=100,
tol_abs_gradnorm=1e-5)
S = ift.create_power_operator(hspace, power_spectrum=_flat_PS)
energy = ift.WienerFilterEnergy(
position=s0, d=d, R=R, N=N, S=S, iteration_controller=IC)
ift.extra.check_value_gradient_metric_consistency(
energy, ntries=10)
@expand(product([ift.GLSpace(15),
ift.RGSpace(64, distances=.789),
ift.RGSpace([32, 32], distances=.789)],
......
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