Commit 33262e78 authored by Martin Reinecke's avatar Martin Reinecke

Merge remote-tracking branch 'origin/NIFTy_5' into vol_corrections

parents 936e6815 c6c876cf
...@@ -39,9 +39,9 @@ test_serial: ...@@ -39,9 +39,9 @@ test_serial:
script: script:
- pytest-3 -q --cov=nifty5 test - pytest-3 -q --cov=nifty5 test
- > - >
python3 -m coverage report --omit "*plot*,*distributed_do*" python3 -m coverage report --omit "*plot*,*distributed_do*" | tee coverage.txt
- > - >
python3 -m coverage report --omit "*plot*,*distributed_do*" | grep TOTAL | awk '{ print "TOTAL: "$4; }' grep TOTAL coverage.txt | awk '{ print "TOTAL: "$4; }'
test_mpi: test_mpi:
stage: test stage: test
...@@ -51,14 +51,16 @@ test_mpi: ...@@ -51,14 +51,16 @@ test_mpi:
- mpiexec -n 2 --bind-to none pytest-3 -q test - mpiexec -n 2 --bind-to none pytest-3 -q test
pages: pages:
# FIXME Build only for main branch and set stage to release stage: release
stage: test
script: script:
- sh docs/generate.sh - sh docs/generate.sh
- mv docs/build/ public/ - mv docs/build/ public/
artifacts: artifacts:
paths: paths:
- public - public
only:
- NIFTy_5
before_script: before_script:
- python3 setup.py install --user -f - python3 setup.py install --user -f
......
...@@ -43,22 +43,22 @@ def exposure_2d(): ...@@ -43,22 +43,22 @@ def exposure_2d():
if __name__ == '__main__': if __name__ == '__main__':
# FIXME All random seeds to 42 # FIXME All random seeds to 42
np.random.seed(41) np.random.seed(42)
# Choose space on which the signal field is defined # Choose space on which the signal field is defined
mode = 2 mode = 1
if mode == 0: if mode == 0:
# One-dimensional regular grid with uniform exposure # One-dimensional regular grid with uniform exposure of 10
position_space = ift.RGSpace(1024) position_space = ift.RGSpace(1024)
exposure = ift.Field.full(position_space, 1.) exposure = ift.Field.full(position_space, 10.)
elif mode == 1: elif mode == 1:
# Two-dimensional regular grid with inhomogeneous exposure # Two-dimensional regular grid with inhomogeneous exposure
position_space = ift.RGSpace([512, 512]) position_space = ift.RGSpace([512, 512])
exposure = exposure_2d() exposure = exposure_2d()
else: else:
# Sphere with uniform exposure # Sphere with uniform exposure of 100
position_space = ift.HPSpace(128) position_space = ift.HPSpace(128)
exposure = ift.Field.full(position_space, 1.) exposure = ift.Field.full(position_space, 100.)
# Define harmonic space and harmonic transform # Define harmonic space and harmonic transform
harmonic_space = position_space.get_default_codomain() harmonic_space = position_space.get_default_codomain()
......
...@@ -17,8 +17,12 @@ ...@@ -17,8 +17,12 @@
############################################################ ############################################################
# Non-linear tomography # Non-linear tomography
# The data is integrated lines of sight #
# Random lines (set mode=0), radial lines (mode=1) # The signal is a sigmoid-normal distributed field.
# The data is the field integrated along lines of sight that are
# randomly (set mode=0) or radially (mode=1) distributed
#
# Demo takes a while to compute
############################################################# #############################################################
import numpy as np import numpy as np
...@@ -28,22 +32,22 @@ import nifty5 as ift ...@@ -28,22 +32,22 @@ import nifty5 as ift
def random_los(n_los): def random_los(n_los):
starts = list(np.random.uniform(0, 1, (n_los, 2)).T) starts = list(np.random.uniform(0, 1, (n_los, 2)).T)
ends = list(0.5 + 0*np.random.uniform(0, 1, (n_los, 2)).T) ends = list(np.random.uniform(0, 1, (n_los, 2)).T)
return starts, ends return starts, ends
def radial_los(n_los): def radial_los(n_los):
starts = list(np.random.uniform(0, 1, (n_los, 2)).T) starts = list(np.random.uniform(0, 1, (n_los, 2)).T)
ends = list(np.random.uniform(0, 1, (n_los, 2)).T) ends = list(0.5 + 0*np.random.uniform(0, 1, (n_los, 2)).T)
return starts, ends return starts, ends
if __name__ == '__main__': if __name__ == '__main__':
np.random.seed(420) np.random.seed(420) # picked for a nice field realization
# Choose between random line-of-sight response (mode=1) and radial lines # Choose between random line-of-sight response (mode=0) and radial lines
# of sight (mode=2) # of sight (mode=1)
mode = 1 mode = 0
position_space = ift.RGSpace([128, 128]) position_space = ift.RGSpace([128, 128])
harmonic_space = position_space.get_default_codomain() harmonic_space = position_space.get_default_codomain()
...@@ -62,8 +66,8 @@ if __name__ == '__main__': ...@@ -62,8 +66,8 @@ if __name__ == '__main__':
# Power-law part of spectrum: # Power-law part of spectrum:
'sm': -5, # preferred power-law slope 'sm': -5, # preferred power-law slope
'sv': .5, # low variance of power-law slope 'sv': .5, # low variance of power-law slope
'im': .4, # y-intercept mean 'im': 0, # y-intercept mean, in-/decrease for more/less contrast
'iv': .3 # relatively high y-intercept variance 'iv': .3 # y-intercept variance
} }
A = ift.SLAmplitude(**dct) A = ift.SLAmplitude(**dct)
...@@ -79,7 +83,7 @@ if __name__ == '__main__': ...@@ -79,7 +83,7 @@ if __name__ == '__main__':
signal = ift.sigmoid(correlated_field) signal = ift.sigmoid(correlated_field)
# Build the line-of-sight response and define signal response # Build the line-of-sight response and define signal response
LOS_starts, LOS_ends = random_los(100) if mode == 1 else radial_los(100) LOS_starts, LOS_ends = random_los(100) if mode == 0 else radial_los(100)
R = ift.LOSResponse(position_space, starts=LOS_starts, ends=LOS_ends) R = ift.LOSResponse(position_space, starts=LOS_starts, ends=LOS_ends)
signal_response = R(signal) signal_response = R(signal)
......
...@@ -44,7 +44,8 @@ def polynomial(coefficients, sampling_points): ...@@ -44,7 +44,8 @@ def polynomial(coefficients, sampling_points):
class PolynomialResponse(ift.LinearOperator): class PolynomialResponse(ift.LinearOperator):
"""Calculates values of a polynomial parameterized by input at sampling points. """Calculates values of a polynomial parameterized by input at sampling
points.
Parameters Parameters
---------- ----------
......
# rm -rf docs/build docs/source/mod rm -rf docs/build docs/source/mod
sphinx-apidoc -e -o docs/source/mod nifty5 sphinx-apidoc -e -o docs/source/mod nifty5
sphinx-build -b html docs/source/ docs/build/ sphinx-build -b html docs/source/ docs/build/
...@@ -41,7 +41,6 @@ Abstract base class ...@@ -41,7 +41,6 @@ Abstract base class
One of the fundamental building blocks of the NIFTy5 framework is the *domain*. One of the fundamental building blocks of the NIFTy5 framework is the *domain*.
Its required capabilities are expressed by the abstract :py:class:`Domain` class. Its required capabilities are expressed by the abstract :py:class:`Domain` class.
A domain must be able to answer the following queries: A domain must be able to answer the following queries:
m
- its total number of data entries (pixels), which is accessible via the - its total number of data entries (pixels), which is accessible via the
:attr:`~Domain.size` property :attr:`~Domain.size` property
...@@ -129,7 +128,7 @@ specify full field domains. In principle, a :class:`~domain_tuple.DomainTuple` ...@@ -129,7 +128,7 @@ specify full field domains. In principle, a :class:`~domain_tuple.DomainTuple`
can even be empty, which implies that the field living on it is a scalar. can even be empty, which implies that the field living on it is a scalar.
A :class:`~domain_tuple.DomainTuple` supports iteration and indexing, and also A :class:`~domain_tuple.DomainTuple` supports iteration and indexing, and also
provides the properties :attr:`~domain_tuple.DomainTuple.shape`, provides the properties :attr:`~domain_tuple.DomainTuple.shape` and
:attr:`~domain_tuple.DomainTuple.size` in analogy to the elementary :attr:`~domain_tuple.DomainTuple.size` in analogy to the elementary
:class:`~domains.domain.Domain`. :class:`~domains.domain.Domain`.
...@@ -159,10 +158,11 @@ Contractions (like summation, integration, minimum/maximum, computation of ...@@ -159,10 +158,11 @@ Contractions (like summation, integration, minimum/maximum, computation of
statistical moments) can be carried out either over an entire field (producing statistical moments) can be carried out either over an entire field (producing
a scalar result) or over sub-domains (resulting in a field defined on a smaller a scalar result) or over sub-domains (resulting in a field defined on a smaller
domain). Scalar products of two fields can also be computed easily. domain). Scalar products of two fields can also be computed easily.
See the documentation of :class:`~field.Field` for details.
There is also a set of convenience functions to generate fields with constant There is also a set of convenience functions to generate fields with constant
values or fields filled with random numbers according to a user-specified values or fields filled with random numbers according to a user-specified
distribution. distribution: :attr:`~sugar.full`, :attr:`~sugar.from_random`.
Like almost all NIFTy objects, fields are immutable: their value or any other Like almost all NIFTy objects, fields are immutable: their value or any other
attribute cannot be modified after construction. To manipulate a field in ways attribute cannot be modified after construction. To manipulate a field in ways
...@@ -311,11 +311,15 @@ and ``f1`` and ``f2`` are of type :class:`~field.Field`, writing:: ...@@ -311,11 +311,15 @@ and ``f1`` and ``f2`` are of type :class:`~field.Field`, writing::
will perform the operation suggested intuitively by the notation, checking will perform the operation suggested intuitively by the notation, checking
domain compatibility while building the composed operator. domain compatibility while building the composed operator.
The combined operator infers its domain and target from its constituents,
as well as the set of operations it can support.
The properties :attr:`~LinearOperator.adjoint` and The properties :attr:`~LinearOperator.adjoint` and
:attr:`~LinearOperator.inverse` return a new operator which behaves as if it :attr:`~LinearOperator.inverse` return a new operator which behaves as if it
were the original operator's adjoint or inverse, respectively. were the original operator's adjoint or inverse, respectively.
The combined operator infers its domain and target from its constituents,
as well as the set of operations it can support.
Instantiating operator adjoints or inverses by :attr:`~LinearOperator.adjoint`
and similar methods is to be distinguished from the instant application of
operators performed by :attr:`~LinearOperator.adjoint_times` and similar
methods.
.. _minimization: .. _minimization:
...@@ -368,8 +372,8 @@ failure. ...@@ -368,8 +372,8 @@ failure.
Sensible stopping criteria can vary significantly with the problem being Sensible stopping criteria can vary significantly with the problem being
solved; NIFTy provides one concrete sub-class of :class:`IterationController` solved; NIFTy provides one concrete sub-class of :class:`IterationController`
called :class:`GradientNormController`, which should be appropriate in many called :class:`GradientNormController`, which should be appropriate in many
circumstances, but users have complete freedom to implement custom sub-classes circumstances, but users have complete freedom to implement custom
for their specific applications. :class:`IterationController` sub-classes for their specific applications.
Minimization algorithms Minimization algorithms
...@@ -424,11 +428,13 @@ the information propagator whose inverse is defined as: ...@@ -424,11 +428,13 @@ the information propagator whose inverse is defined as:
:math:`D^{-1} = \left(R^\dagger N^{-1} R + S^{-1}\right)`. :math:`D^{-1} = \left(R^\dagger N^{-1} R + S^{-1}\right)`.
It needs to be applied in forward direction in order to calculate the Wiener It needs to be applied in forward direction in order to calculate the Wiener
filter solution. Only its inverse application is straightforward; to use it in filter solution, but only its inverse application is straightforward.
forward direction, we make use of NIFTy's To use it in forward direction, we make use of NIFTy's
:class:`~operators.inversion_enabler.InversionEnabler` class, which internally :class:`~operators.inversion_enabler.InversionEnabler` class, which internally
performs a minimization of a applies the (approximate) inverse of the given operator :math:`x = Op^{-1} (y)` by
:class:`~minimization.quadratic_energy.QuadraticEnergy` by means of the solving the equation :math:`y = Op (x)` for :math:`x`.
:class:`~minimization.conjugate_gradient.ConjugateGradient` algorithm. An This is accomplished by minimizing a suitable
example is provided in :class:`~minimization.quadratic_energy.QuadraticEnergy`
with the :class:`~minimization.conjugate_gradient.ConjugateGradient`
algorithm. An example is provided in
:func:`~library.wiener_filter_curvature.WienerFilterCurvature`. :func:`~library.wiener_filter_curvature.WienerFilterCurvature`.
...@@ -4,9 +4,6 @@ IFT -- Information Field Theory ...@@ -4,9 +4,6 @@ IFT -- Information Field Theory
Theoretical Background Theoretical Background
---------------------- ----------------------
Introduction
............
`Information Field Theory <http://www.mpa-garching.mpg.de/ift/>`_ [1]_ (IFT) is information theory, the logic of reasoning under uncertainty, applied to fields. `Information Field Theory <http://www.mpa-garching.mpg.de/ift/>`_ [1]_ (IFT) is information theory, the logic of reasoning under uncertainty, applied to fields.
A field can be any quantity defined over some space, e.g. the air temperature over Europe, the magnetic field strength in the Milky Way, or the matter density in the Universe. A field can be any quantity defined over some space, e.g. the air temperature over Europe, the magnetic field strength in the Milky Way, or the matter density in the Universe.
IFT describes how data and knowledge can be used to infer field properties. IFT describes how data and knowledge can be used to infer field properties.
......
NIFTy -- Numerical Information Field Theory NIFTy -- Numerical Information Field Theory
=========================================== ===========================================
**NIFTy** [1]_, [2]_, "\ **N**\umerical **I**\nformation **F**\ield **T**\heor\ **y**\ ", is a versatile library designed to enable the development of signal inference algorithms that are independent of the underlying spatial grid and its resolution. **NIFTy** [1]_, [2]_, "\ **N**\umerical **I**\nformation **F**\ield **T**\heor\ **y**\ ", is a versatile library designed to enable the development of signal inference algorithms that are independent of the underlying grids (spatial, spectral, temporal, …) and their resolutions.
Its object-oriented framework is written in Python, although it accesses libraries written in C++ and C for efficiency. Its object-oriented framework is written in Python, although it accesses libraries written in C++ and C for efficiency.
NIFTy offers a toolkit that abstracts discretized representations of continuous spaces, fields in these spaces, and operators acting on fields into classes. NIFTy offers a toolkit that abstracts discretized representations of continuous spaces, fields in these spaces, and operators acting on these fields into classes.
Thereby, the correct normalization of operations on fields is taken care of automatically without concerning the user.
This allows for an abstract formulation and programming of inference algorithms, including those derived within information field theory. This allows for an abstract formulation and programming of inference algorithms, including those derived within information field theory.
Thus, NIFTy permits its user to rapidly prototype algorithms in 1D and then apply the developed code in higher-dimensional settings to real world problems. NIFTy's interface is designed to resemble IFT formulae in the sense that the user implements algorithms in NIFTy independent of the topology of the underlying spaces and the discretization scheme.
Thus, the user can develop algorithms on subsets of problems and on spaces where the detailed performance of the algorithm can be properly evaluated and then easily generalize them to other, more complex spaces and the full problem, respectively.
The set of spaces on which NIFTy operates comprises point sets, *n*-dimensional regular grids, spherical spaces, their harmonic counterparts, and product spaces constructed as combinations of those. The set of spaces on which NIFTy operates comprises point sets, *n*-dimensional regular grids, spherical spaces, their harmonic counterparts, and product spaces constructed as combinations of those.
NIFTy takes care of numerical subtleties like the normalization of operations on fields and the numerical representation of model components, allowing the user to focus on formulating the abstract inference procedures and process-specific model properties.
References References
---------- ----------
...@@ -21,6 +23,7 @@ Contents ...@@ -21,6 +23,7 @@ Contents
........ ........
.. toctree:: .. toctree::
:maxdepth: 2
ift ift
volume volume
......
...@@ -14,12 +14,13 @@ Plotting support is added via:: ...@@ -14,12 +14,13 @@ Plotting support is added via::
pip3 install --user matplotlib pip3 install --user matplotlib
FFTW support is added via:: NIFTy uses Numpy's FFT implementation by default. For large problems FFTW may be
used because of its higher performance. It can be installed via::
sudo apt-get install libfftw3-dev sudo apt-get install libfftw3-dev
pip3 install --user pyfftw pip3 install --user pyfftw
To actually use FFTW in your Nifty calculations, you need to call:: To enable FFTW usage in NIFTy, call::
nifty5.fft.enable_fftw() nifty5.fft.enable_fftw()
......
...@@ -86,7 +86,10 @@ class Domain(metaclass=NiftyMeta): ...@@ -86,7 +86,10 @@ class Domain(metaclass=NiftyMeta):
@property @property
def local_shape(self): def local_shape(self):
"""tuple of int: number of pixels along each axis on the local task """tuple of int: number of pixels along each axis on the local task,
mainly relevant for MPI.
See :meth:`.shape()` for general explanation of property.
The shape of the array-like object required to store information The shape of the array-like object required to store information
defined on part of the domain which is stored on the local MPI task. defined on part of the domain which is stored on the local MPI task.
......
...@@ -87,11 +87,11 @@ class StructuredDomain(Domain): ...@@ -87,11 +87,11 @@ class StructuredDomain(Domain):
def get_fft_smoothing_kernel_function(self, sigma): def get_fft_smoothing_kernel_function(self, sigma):
"""Helper for Gaussian smoothing. """Helper for Gaussian smoothing.
This method, which is only implemented for harmonic domains, helps This method, which is only implemented for harmonic domains, helps to
smoothing fields that are defined on a domain that has this domain as smoothe fields that are defined on a domain that has this domain as
its harmonic partner. The returned function multiplies field values of its harmonic partner. The returned function does a pointwise evaluation
a field with a zero centered Gaussian which corresponds to a of a zero-centered Gaussian on the field values, which corresponds to a
convolution with a Gaussian kernel and sigma standard deviation in convolution with a Gaussian kernel with sigma standard deviation in
position space. position space.
Parameters Parameters
......
...@@ -171,4 +171,3 @@ def check_jacobian_consistency(op, loc, tol=1e-8, ntries=100): ...@@ -171,4 +171,3 @@ def check_jacobian_consistency(op, loc, tol=1e-8, ntries=100):
else: else:
raise ValueError("gradient and value seem inconsistent") raise ValueError("gradient and value seem inconsistent")
loc = locnext loc = locnext
...@@ -97,24 +97,24 @@ def _cone_arrays(c, domain, sigx, want_gradient): ...@@ -97,24 +97,24 @@ def _cone_arrays(c, domain, sigx, want_gradient):
class LightConeOperator(Operator): class LightConeOperator(Operator):
'''Constructs a Light cone from a set of lightspeed parameters. '''Constructs a Light cone from a set of lightspeed parameters.
The resulting cone is defined as follows The resulting cone is defined as follows
.. math:: .. math::
\\exp \\left(- \\frac{1}{2} \\Re \\left( \\Delta \\right)^2 \\right) \\exp \\left(- \\frac{1}{2} \\Re \\left( \\Delta \\right)^2 \\right)
with with
.. math:: .. math::
\\Delta = \\sqrt{- \\left(t^2 - \\frac{x^\\dagger C^{-1} x} \\Delta = \\sqrt{- \\left(t^2 - \\frac{x^\\dagger C^{-1} x}
{\\sigma_x^2} \\right)} {\\sigma_x^2} \\right)}
where t and x are the coordinates of the target space. Note that axis zero where t and x are the coordinates of the target space. Note that axis zero
of the space is interpreted as the time axis. C denotes the input of the space is interpreted as the time axis. C denotes the input
paramters of the operator and parametrizes the shape of the cone. paramters of the operator and parametrizes the shape of the cone.
sigx is the width of the asymptotic Gaussian in x necessary for sigx is the width of the asymptotic Gaussian in x necessary for
discretization. discretization.
Parameters Parameters
---------- ----------
domain : Domain, tuple of Domain or DomainTuple domain : Domain, tuple of Domain or DomainTuple
......
...@@ -31,8 +31,8 @@ class ExpTransform(LinearOperator): ...@@ -31,8 +31,8 @@ class ExpTransform(LinearOperator):
This operator creates a log-space subject to the degrees of freedom and This operator creates a log-space subject to the degrees of freedom and
and its target-domain. and its target-domain.
Then it transforms between this log-space and its target, which is defined in Then it transforms between this log-space and its target, which is defined
normal units. in normal units.
FIXME Write something on t_0 of domain space FIXME Write something on t_0 of domain space
......
...@@ -366,8 +366,14 @@ class Plot(object): ...@@ -366,8 +366,14 @@ class Plot(object):
fig = plt.figure() fig = plt.figure()
if "title" in kwargs: if "title" in kwargs:
plt.suptitle(kwargs.pop("title")) plt.suptitle(kwargs.pop("title"))
nx = kwargs.pop("nx", int(np.ceil(np.sqrt(nplot)))) nx = kwargs.pop("nx", 0)
ny = kwargs.pop("ny", int(np.ceil(np.sqrt(nplot)))) ny = kwargs.pop("ny", 0)
if nx == ny == 0:
nx = ny = int(np.ceil(np.sqrt(nplot)))
elif nx == 0:
nx = np.ceil(nplot/ny)
elif ny == 0:
ny = np.ceil(nplot/nx)
if nx*ny < nplot: if nx*ny < nplot:
raise ValueError( raise ValueError(
'Figure dimensions not sufficient for number of plots. ' 'Figure dimensions not sufficient for number of plots. '
......
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