start.rst 7.6 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
5
6
7
8
9
10
11
12
.. _informal_label:

First steps -- An informal introduction
=======================================

NIFTy4 Tutorial
---------------

.. currentmodule:: nifty4

.. automodule:: nifty4

13
NIFTy4 enables the programming of grid and resolution independent algorithms.
Martin Reinecke's avatar
fixes  
Martin Reinecke committed
14
15
16
This freedom is particularly desirable for signal inference algorithms, where
a continuous signal field is to be recovered.
It is achieved by means of an object-oriented infrastructure that comprises, among others, abstract classes for :ref:`Domains <domains>`, :ref:`Fields <fields>`, and :ref:`Operators <operators>`.
17
All those are covered in this tutorial.
Martin Reinecke's avatar
Martin Reinecke committed
18
19
20
21
22

You should be able to import NIFTy4 like this after a successful `installation <install.html>`_.

>>> import nifty4 as ift

Martin Reinecke's avatar
Martin Reinecke committed
23
24
25
26
27
28
29
30
31
32
33

Technical bird's eye view
.........................

The fundamental building blocks required for IFT computations are best recognized from a large distance, ignoring all technical details.

From such a perspective,

- IFT problems largely consist of *minimization* problems involving a large number of equations.
- The equations are built mostly from the application of *linear operators*, but there may also be nonlinear functions involved.
- The unknowns in the equations represent either continuous physical *fields*, or they are simply individual measured *data* points.
Martin Reinecke's avatar
fixes  
Martin Reinecke committed
34
- The locations and volume elements attached to discretized *field* values are supplied by *domain* objects. There are many variants of such discretized *domain* supported by NIFTy4, including Cartesian and spherical geometries and their harmonic counterparts. *Fields* can live on arbitrary products of such *domains*.
Martin Reinecke's avatar
Martin Reinecke committed
35
36
37
38

In the following sections, the concepts briefly presented here will be discussed in more detail; this is done in reversed order of their introduction, to avoid forward references.


39
40
41
42
43
44
45
46
47
48
49
.. _domainobjects:

DomainObjects
.............

One of the fundamental building blocks of the NIFTy4 framework is the /domain/.
Its required capabilities are expressed by the abstract :py:class:`DomainObject` class.
A domain must be able to answer the following queries:

- its total number of data entries (pixels)
- the shape of the array that is supposed to hold them
Philipp Arras's avatar
Philipp Arras committed
50
- equality/inequality to another :py:class:`DomainObject` instance
51

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
52
.. _domains:
Martin Reinecke's avatar
Martin Reinecke committed
53

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
54
55
Unstructured domains
....................
56
57

There are domains (e.g. the data domain) which have no geometry associated to the individual data values.
Martin Reinecke's avatar
fixes  
Martin Reinecke committed
58
59
In NIFTy4 they are represented by the :py:class:`UnstructuredDomain` class, which is derived from
:py:class:`DomainObject`.
Martin Reinecke's avatar
Martin Reinecke committed
60
61


Martin Reinecke's avatar
fixes  
Martin Reinecke committed
62
63
Structured domains
..................
64

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
65
All domains defined on a geometrical manifold are derived from :py:class:`StructuredDomain` (which is in turn derived from :py:class:`DomainObject`).
66

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
67
In addition to the capabilities of :py:class:`DomainObject`, :py:class:`StructuredDomain` offers the following functionality:
68

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
69
- methods returing the pixel volume(s) and the total volume
70
- a :py:attr:`harmonic` property
Martin Reinecke's avatar
fixes  
Martin Reinecke committed
71
- (iff the domain is harmonic) some methods concerned with Gaussian convolution and the absolute distances of the individual grid cells from the origin
72

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
73
Examples for structured domains are
Martin Reinecke's avatar
Martin Reinecke committed
74
75
76
77
78

- :py:class:`RGSpace` (an equidistant Cartesian grid with a user-definable number of dimensions),
- :py:class:`GLSpace` (a Gauss-Legendre grid on the sphere), and
- :py:class:`LMSpace` (a grid storing spherical harmonic coefficients).

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
79
Among these, :py:class:`RGSpace` can be harmonic or not (depending on constructor arguments), :py:class:`GLSpace` is a pure position domain (i.e. nonharmonic), and :py:class:`LMSpace` is always harmonic.
Martin Reinecke's avatar
Martin Reinecke committed
80

81
82
Full domains
............
Martin Reinecke's avatar
Martin Reinecke committed
83

Martin Reinecke's avatar
fixes  
Martin Reinecke committed
84
85
A field can live on a single domain, but it can also live on a product of domains (or no domain at all, in which case it is a scalar).
The tuple of domain on which a field lives is described by the :py:class:`DomainTuple` class.
86
87
88
89
90
A :py:class:`DomainTuple` object can be constructed from

- a single instance of anything derived from :py:class:`DomainTuple`
- a tuple of such instances (possibly empty)
- another :py:class:`DomainTuple` object
Martin Reinecke's avatar
Martin Reinecke committed
91
92
93
94

.. _fields:

Fields
95
......
Martin Reinecke's avatar
Martin Reinecke committed
96

97
A :py:class:`Field` object consists of the following components:
Martin Reinecke's avatar
Martin Reinecke committed
98
99
100
101
102
103
104
105
106

- a domain in form of a :py:class:`DomainTuple` object
- a data type (e.g. numpy.float64)
- an array containing the actual values

Fields support arithmetic operations, contractions, etc.

.. _operators:

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Linear Operators
................

A linear operator (represented by NIFTy4's abstract :py:class:`LinearOperator` class) can be interpreted as an (implicitly defined) matrix.
It can be applied to :py:class:`Field` instances, resulting in other :py:class:`Field` instances that potentially live on other domains.

There are four basic ways of applying an operator :math:`A` to a field :math:`f`:

- direct multiplication: :math:`A\cdot f`
- adjoint multiplication: :math:`A^\dagger \cdot f`
- inverse multiplication: :math:`A^{-1}\cdot f`
- adjoint inverse multiplication: :math:`(A^\dagger)^{-1}\cdot f`

(For linear operators, inverse adjoint multiplication and adjoint inverse multiplication are equivalent.)

Operator classes defined in NIFTy may implement an arbitrary subset of these four operations.
If needed, the set of supported operations can be enhanced by iterative inversion methods;
for example, an operator defining direct and adjoint multiplication, could be enhanced to support the complete set by this method.

There are two domains associated with a :py:class:`LinearOperator`: a *domain* and a *target*.
Direct multiplication and adjoint inverse multiplication transform a field living on the operator's *domain* to one living on the operator's *target*, whereas adjoint multiplication and inverse multiplication transform from *target* to *domain*.

Operators with identical domain and target can be derived from :py:class:`EndomorphicOperator`;
typical examples for this category are the :py:class:`ScalingOperator`, which simply multiplies its input by a scalar value and :py:class:`DiagonalOperator`, which multiplies every value of its input field with potentially different values.

Nifty4 allows simple and intuitive construction of combined operators.
As an example, if :math:`A`, :math:`B` and :math:`C` are of type :py:class:`LinearOperator` and :math:`f_1` and :math:`f_2` are fields, writing::
Martin Reinecke's avatar
Martin Reinecke committed
134

135
136
137
138
    X = A*B.inverse*A.adjoint + C
    f2 = X(f1)

will perform the operation suggested intuitively by the notation, checking domain compatibility while building the composed operator.
Martin Reinecke's avatar
Martin Reinecke committed
139
The combined operator infers its domain and target from its constituents, as well as the set of operations it can support.
140
141
142


.. _minimization:
Martin Reinecke's avatar
Martin Reinecke committed
143

144
145
Minimization
............
Martin Reinecke's avatar
Martin Reinecke committed
146
147
148
149
150
151
152
153
154
155

Most problems in IFT are solved by (possibly nested) minimizations of high-dimensional functions, which are often nonlinear.

In NIFTy4 such functions are represented by objects of type :py:class:`Energy`.
These hold the prescription how to calculate the function's value, gradient and (optionally) curvature at any given position.
Function values are floating-point scalars, gradients have the form of fields living on the energy's position domain, and curvatures are represented by linear operator objects.

Some examples of concrete energy classes delivered with NIFTy4 are :py:class:`QuadraticEnergy` (with position-independent curvature, mainly used with conjugate gradient minimization) and :py:class:`WienerFilterEnergy`.
Energies are classes that typically have to be provided by the user when tackling new IFT problems.

Martin Reinecke's avatar
typo  
Martin Reinecke committed
156
The minimization procedure can be carried out by one of several algorithms; NIFTy4 currently ships solvers based on
Martin Reinecke's avatar
Martin Reinecke committed
157
158
159
160
161
162
163

- the conjugate gradient method (for quadratic energies)
- the steepest descent method
- the VL-BFGS method
- the relaxed Newton method, and
- a nonlinear conjugate gradient method