Commit 268962e3 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'NIFTy_5' into move_dynamic_prior

parents 4a9980ba 928858f4
...@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \ ...@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y \
libfftw3-dev \ libfftw3-dev \
python3 python3-pip python3-dev python3-future python3-scipy cython3 \ python3 python3-pip python3-dev python3-future python3-scipy cython3 \
# Documentation build dependencies # Documentation build dependencies
python3-sphinx python3-sphinx-rtd-theme python3-numpydoc \ python3-sphinx python3-sphinx-rtd-theme \
# Testing dependencies # Testing dependencies
python3-coverage python3-pytest python3-pytest-cov \ python3-coverage python3-pytest python3-pytest-cov \
# Optional NIFTy dependencies # Optional NIFTy dependencies
......
rm -rf docs/build docs/source/mod
sphinx-apidoc -l -e -d 2 -o docs/source/mod nifty5 sphinx-apidoc -l -e -d 2 -o docs/source/mod nifty5
sphinx-build -b html docs/source/ docs/build/ sphinx-build -b html docs/source/ docs/build/
.. currentmodule:: nifty5
============= =============
Code Overview Code Overview
...@@ -37,9 +36,12 @@ Domains ...@@ -37,9 +36,12 @@ Domains
Abstract base class Abstract base class
------------------- -------------------
.. currentmodule:: nifty5.domains.domain
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 :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
...@@ -51,6 +53,8 @@ A domain must be able to answer the following queries: ...@@ -51,6 +53,8 @@ A domain must be able to answer the following queries:
Unstructured domains Unstructured domains
-------------------- --------------------
.. currentmodule:: nifty5.domains.unstructured_domain
Domains can be either *structured* (i.e. there is geometrical information Domains can be either *structured* (i.e. there is geometrical information
associated with them, like position in space and volume factors), associated with them, like position in space and volume factors),
or *unstructured* (meaning that the data points have no associated manifold). or *unstructured* (meaning that the data points have no associated manifold).
...@@ -62,6 +66,8 @@ Unstructured domains can be described by instances of NIFTy's ...@@ -62,6 +66,8 @@ Unstructured domains can be described by instances of NIFTy's
Structured domains Structured domains
------------------ ------------------
.. currentmodule:: nifty5.domains.structured_domain
In contrast to unstructured domains, these domains have an assigned geometry. In contrast to unstructured domains, these domains have an assigned geometry.
NIFTy requires them to provide the volume elements of their grid cells. NIFTy requires them to provide the volume elements of their grid cells.
The additional methods are specified in the abstract class The additional methods are specified in the abstract class
...@@ -81,15 +87,17 @@ The additional methods are specified in the abstract class ...@@ -81,15 +87,17 @@ The additional methods are specified in the abstract class
NIFTy comes with several concrete subclasses of :class:`StructuredDomain`: NIFTy comes with several concrete subclasses of :class:`StructuredDomain`:
- :class:`RGSpace` represents a regular Cartesian grid with an arbitrary .. currentmodule:: nifty5.domains
- :class:`rg_space.RGSpace` represents a regular Cartesian grid with an arbitrary
number of dimensions, which is supposed to be periodic in each dimension. number of dimensions, which is supposed to be periodic in each dimension.
- :class:`HPSpace` and :class:`GLSpace` describe pixelisations of the - :class:`hp_space.HPSpace` and :class:`gl_space.GLSpace` describe pixelisations of the
2-sphere; their counterpart in harmonic space is :class:`LMSpace`, which 2-sphere; their counterpart in harmonic space is :class:`lm_space.LMSpace`, which
contains spherical harmonic coefficients. contains spherical harmonic coefficients.
- :class:`PowerSpace` is used to describe one-dimensional power spectra. - :class:`power_space.PowerSpace` is used to describe one-dimensional power spectra.
Among these, :class:`RGSpace` can be harmonic or not (depending on constructor arguments), :class:`GLSpace`, :class:`HPSpace`, and :class:`PowerSpace` are Among these, :class:`rg_space.RGSpace` can be harmonic or not (depending on constructor arguments), :class:`gl_space.GLSpace`, :class:`hp_space.HPSpace`, and :class:`power_space.PowerSpace` are
pure position domains (i.e. nonharmonic), and :class:`LMSpace` is always pure position domains (i.e. nonharmonic), and :class:`lm_space.LMSpace` is always
harmonic. harmonic.
...@@ -158,7 +166,7 @@ be extracted first, then changed, and a new field has to be created from the ...@@ -158,7 +166,7 @@ be extracted first, then changed, and a new field has to be created from the
result. result.
Fields defined on a MultiDomain Fields defined on a MultiDomain
------------------------------ -------------------------------
The :class:`MultiField` class can be seen as a dictionary of individual The :class:`MultiField` class can be seen as a dictionary of individual
:class:`Field` s, each identified by a name, which is defined on a :class:`Field` s, each identified by a name, which is defined on a
...@@ -300,7 +308,7 @@ As an example one may consider the following combination of ``x``, which is an o ...@@ -300,7 +308,7 @@ As an example one may consider the following combination of ``x``, which is an o
Basic operators Basic operators
------------ ---------------
# FIXME All this is outdated! # FIXME All this is outdated!
Basic operator classes provided by NIFTy are Basic operator classes provided by NIFTy are
......
import nifty5 import nifty5
import sphinx_rtd_theme
napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_use_ivar = True
napoleon_use_param = False
napoleon_use_keyword = False
autodoc_member_order = 'groupwise'
numpydoc_show_inherited_class_members = False
numpydoc_class_members_toctree = False
extensions = [ extensions = [
'sphinx.ext.autodoc', 'numpydoc', 'sphinx.ext.autosummary', 'sphinx.ext.napoleon', # Support for NumPy and Google style docstrings
'sphinx.ext.napoleon', 'sphinx.ext.imgmath', 'sphinx.ext.viewcode' 'sphinx.ext.imgmath', # Render math as images
'sphinx.ext.viewcode' # Add links to highlighted source code
] ]
templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_use_ivar = True
project = u'NIFTy5' project = u'NIFTy5'
copyright = u'2013-2019, Max-Planck-Society' copyright = u'2013-2019, Max-Planck-Society'
author = u'Martin Reinecke' author = u'Martin Reinecke'
...@@ -29,19 +21,6 @@ version = release[:-2] ...@@ -29,19 +21,6 @@ version = release[:-2]
language = None language = None
exclude_patterns = [] exclude_patterns = []
add_module_names = False add_module_names = False
pygments_style = 'sphinx'
todo_include_todos = True
html_theme = "sphinx_rtd_theme" html_theme = "sphinx_rtd_theme"
html_theme_options = {
'collapse_navigation': False,
'display_version': False,
}
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_logo = 'nifty_logo_black.png' html_logo = 'nifty_logo_black.png'
html_static_path = []
html_last_updated_fmt = '%b %d, %Y'
html_domain_indices = False
html_use_index = False
html_show_sourcelink = False
htmlhelp_basename = 'NIFTydoc'
...@@ -104,6 +104,7 @@ with :math:`{R}` the measurement response, which maps the continous signal field ...@@ -104,6 +104,7 @@ with :math:`{R}` the measurement response, which maps the continous signal field
This is called a free theory, as the information Hamiltonian This is called a free theory, as the information Hamiltonian
associate professor associate professor
.. math:: .. math::
\mathcal{H}(d,s)= -\log \mathcal{P}(d,s)= \frac{1}{2} s^\dagger S^{-1} s + \frac{1}{2} (d-R\,s)^\dagger N^{-1} (d-R\,s) + \mathrm{const} \mathcal{H}(d,s)= -\log \mathcal{P}(d,s)= \frac{1}{2} s^\dagger S^{-1} s + \frac{1}{2} (d-R\,s)^\dagger N^{-1} (d-R\,s) + \mathrm{const}
...@@ -179,23 +180,22 @@ NIFTy takes advantage of this formulation in several ways: ...@@ -179,23 +180,22 @@ NIFTy takes advantage of this formulation in several ways:
The reconstruction of a non-Gaussian signal with unknown covarinance from a non-trivial (tomographic) response is demonstrated in demos/getting_started_3.py. Here, the uncertainty of the field and the power spectrum of its generating process are probed via posterior samples provided by the MGVI algorithm. The reconstruction of a non-Gaussian signal with unknown covarinance from a non-trivial (tomographic) response is demonstrated in demos/getting_started_3.py. Here, the uncertainty of the field and the power spectrum of its generating process are probed via posterior samples provided by the MGVI algorithm.
+-------------------------------------------------+ +----------------------------------------------------+
| .. image:: images/getting_started_3_setup.png | | **Output of tomography demo getting_started_3.py** |
| :width: 30 % | +----------------------------------------------------+
+-------------------------------------------------+ | .. image:: images/getting_started_3_setup.png |
| .. image:: images/getting_started_3_results.png | | |
| :width: 30 % | +----------------------------------------------------+
+-------------------------------------------------+ | Non-Gaussian signal field, |
| Output of tomography demo getting_started_3.py. | | data backprojected into the image domain, power |
| **Top row:** Non-Gaussian signal field, | | spectrum of underlying Gausssian process. |
| data backprojected into the image domain, power | +----------------------------------------------------+
| spectrum of underlying Gausssian process. | | .. image:: images/getting_started_3_results.png |
| **Bottom row:** Posterior mean field signal | | |
| reconstruction, its uncertainty, and the power | +----------------------------------------------------+
| spectrum of the process for different posterior | | Posterior mean field signal |
| samples in comparison to the correct one (thick | | reconstruction, its uncertainty, and the power |
| orange line). | | spectrum of the process for different posterior |
+-------------------------------------------------+ | samples in comparison to the correct one (thick |
| orange line). |
+----------------------------------------------------+
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import sys import sys
from functools import reduce from functools import reduce
import numpy as np import numpy as np
from mpi4py import MPI from mpi4py import MPI
......
...@@ -18,11 +18,10 @@ ...@@ -18,11 +18,10 @@
# Data object module for NIFTy that uses simple numpy ndarrays. # Data object module for NIFTy that uses simple numpy ndarrays.
import numpy as np import numpy as np
from numpy import empty, empty_like, exp, full, log from numpy import absolute, clip, cos, cosh, empty, empty_like, exp, full, log
from numpy import ndarray as data_object from numpy import ndarray as data_object
from numpy import ones, sqrt, tanh, vdot, zeros from numpy import ones, sign, sin, sinc, sinh, sqrt, tan, tanh, vdot, zeros
from numpy import sin, cos, tan, sinh, cosh, sinc
from numpy import absolute, sign, clip
from .random import Random from .random import Random
__all__ = ["ntask", "rank", "master", "local_shape", "data_object", "full", __all__ = ["ntask", "rank", "master", "local_shape", "data_object", "full",
......
...@@ -111,23 +111,27 @@ def _SlopePowerSpectrum(logk_space, sm, sv, im, iv): ...@@ -111,23 +111,27 @@ def _SlopePowerSpectrum(logk_space, sm, sv, im, iv):
def AmplitudeOperator(s_space, Npixdof, ceps_a, ceps_k, sm, sv, im, iv, def AmplitudeOperator(s_space, Npixdof, ceps_a, ceps_k, sm, sv, im, iv,
keys=['tau', 'phi'], zero_mode=True): keys=['tau', 'phi'], zero_mode=True):
''' ''' Operator for parametrizing smooth power spectra.
Computes a smooth power spectrum. Computes a smooth power spectrum.
Output is defined on a PowerSpace. Output is defined on a PowerSpace.
Parameters Parameters
---------- ----------
Npixdof : int
Npixdof : #pix in dof_space #pix in dof_space
ceps_a : float
ceps_a, ceps_k0 : Smoothness parameters in ceps_kernel Smoothness parameters in ceps_kernel eg. ceps_kernel(k) = (a/(1+(k/k0)**2))**2 a = ceps_a, k0 = ceps_k0
eg. ceps_kernel(k) = (a/(1+(k/k0)**2))**2 ceps_k0 : float
a = ceps_a, k0 = ceps_k0 Smoothness parameters in ceps_kernel eg. ceps_kernel(k) = (a/(1+(k/k0)**2))**2 a = ceps_a, k0 = ceps_k0
sm : float
sm, sv : slope_mean = expected exponent of power law (e.g. -4), slope_mean = expected exponent of power law (e.g. -4)
slope_variance (default=1) sv : float
slope_variance (default=1)
im, iv : y-intercept_mean, y-intercept_variance of power_slope im : float
y-intercept_mean
iv : float
y-intercept_variance of power_slope
''' '''
from ..operators.exp_transform import ExpTransform from ..operators.exp_transform import ExpTransform
......
...@@ -110,11 +110,11 @@ class Linearization(object): ...@@ -110,11 +110,11 @@ class Linearization(object):
def __truediv__(self, other): def __truediv__(self, other):
if isinstance(other, Linearization): if isinstance(other, Linearization):
return self.__mul__(other.inverse()) return self.__mul__(other.one_over())
return self.__mul__(1./other) return self.__mul__(1./other)
def __rtruediv__(self, other): def __rtruediv__(self, other):
return self.inverse().__mul__(other) return self.one_over().__mul__(other)
def __pow__(self, power): def __pow__(self, power):
if not np.isscalar(power): if not np.isscalar(power):
...@@ -122,9 +122,6 @@ class Linearization(object): ...@@ -122,9 +122,6 @@ class Linearization(object):
return self.new(self._val**power, return self.new(self._val**power,
makeOp(self._val**(power-1)).scale(power)(self._jac)) makeOp(self._val**(power-1)).scale(power)(self._jac))
def inverse(self):
return self.new(1./self._val, makeOp(-1./(self._val**2))(self._jac))
def __mul__(self, other): def __mul__(self, other):
from .sugar import makeOp from .sugar import makeOp
if isinstance(other, Linearization): if isinstance(other, Linearization):
......
...@@ -23,18 +23,18 @@ from .linear_operator import LinearOperator ...@@ -23,18 +23,18 @@ from .linear_operator import LinearOperator
class DomainTupleFieldInserter(LinearOperator): class DomainTupleFieldInserter(LinearOperator):
def __init__(self, domain, new_space, index, position): '''Writes the content of a field into one slice of a DomainTuple.
'''Writes the content of a field into one slice of a DomainTuple.
Parameters Parameters
---------- ----------
domain : Domain, tuple of Domain or DomainTuple domain : Domain, tuple of Domain or DomainTuple
new_space : Domain, tuple of Domain or DomainTuple new_space : Domain, tuple of Domain or DomainTuple
index : Integer index : Integer
Index at which new_space shall be added to domain. Index at which new_space shall be added to domain.
position : tuple position : tuple
Slice in new_space in which the input field shall be written into. Slice in new_space in which the input field shall be written into.
''' '''
def __init__(self, domain, new_space, index, position):
self._domain = DomainTuple.make(domain) self._domain = DomainTuple.make(domain)
tgt = list(self.domain) tgt = list(self.domain)
tgt.insert(index, new_space) tgt.insert(index, new_space)
......
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