start.rst 7.6 KB
Newer Older
 Martin Reinecke committed Jan 22, 2018 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  Martin Reinecke committed Jan 22, 2018 13 NIFTy4 enables the programming of grid and resolution independent algorithms.  Martin Reinecke committed Feb 06, 2018 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 , :ref:Fields , and :ref:Operators .  Martin Reinecke committed Jan 22, 2018 17 All those are covered in this tutorial.  Martin Reinecke committed Jan 22, 2018 18 19 20 21 22  You should be able to import NIFTy4 like this after a successful installation _. >>> import nifty4 as ift  Martin Reinecke committed Jan 31, 2018 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 committed Feb 06, 2018 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 committed Jan 31, 2018 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.  Martin Reinecke committed Jan 22, 2018 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 committed Feb 06, 2018 50 - equality/inequality to another :py:class:DomainObject instance  Martin Reinecke committed Jan 22, 2018 51   Martin Reinecke committed Feb 06, 2018 52 .. _domains:  Martin Reinecke committed Jan 22, 2018 53   Martin Reinecke committed Feb 06, 2018 54 55 Unstructured domains ....................  Martin Reinecke committed Jan 22, 2018 56 57  There are domains (e.g. the data domain) which have no geometry associated to the individual data values.  Martin Reinecke committed Feb 06, 2018 58 59 In NIFTy4 they are represented by the :py:class:UnstructuredDomain class, which is derived from :py:class:DomainObject.  Martin Reinecke committed Jan 22, 2018 60 61   Martin Reinecke committed Feb 06, 2018 62 63 Structured domains ..................  Martin Reinecke committed Jan 22, 2018 64   Martin Reinecke committed Feb 06, 2018 65 All domains defined on a geometrical manifold are derived from :py:class:StructuredDomain (which is in turn derived from :py:class:DomainObject).  Martin Reinecke committed Jan 22, 2018 66   Martin Reinecke committed Feb 06, 2018 67 In addition to the capabilities of :py:class:DomainObject, :py:class:StructuredDomain offers the following functionality:  Martin Reinecke committed Jan 22, 2018 68   Martin Reinecke committed Feb 06, 2018 69 - methods returing the pixel volume(s) and the total volume  Martin Reinecke committed Jan 22, 2018 70 - a :py:attr:harmonic property  Martin Reinecke committed Feb 06, 2018 71 - (iff the domain is harmonic) some methods concerned with Gaussian convolution and the absolute distances of the individual grid cells from the origin  Martin Reinecke committed Jan 22, 2018 72   Martin Reinecke committed Feb 06, 2018 73 Examples for structured domains are  Martin Reinecke committed Jan 22, 2018 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 committed Feb 06, 2018 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 committed Jan 22, 2018 80   Martin Reinecke committed Jan 22, 2018 81 82 Full domains ............  Martin Reinecke committed Jan 22, 2018 83   Martin Reinecke committed Feb 06, 2018 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.  Martin Reinecke committed Jan 22, 2018 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 committed Jan 22, 2018 91 92 93 94  .. _fields: Fields  Martin Reinecke committed Jan 22, 2018 95 ......  Martin Reinecke committed Jan 22, 2018 96   Martin Reinecke committed Jan 22, 2018 97 A :py:class:Field object consists of the following components:  Martin Reinecke committed Jan 22, 2018 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:  Martin Reinecke committed Jan 22, 2018 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 134 135 136 137 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:: 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 committed Jan 23, 2018 138 The combined operator infers its domain and target from its constituents, as well as the set of operations it can support.  Martin Reinecke committed Jan 22, 2018 139 140 141  .. _minimization:  Martin Reinecke committed Jan 22, 2018 142   Martin Reinecke committed Jan 22, 2018 143 144 Minimization ............  Martin Reinecke committed Jan 23, 2018 145 146 147 148 149 150 151 152 153 154  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 committed Feb 06, 2018 155 The minimization procedure can be carried out by one of several algorithms; NIFTy4 currently ships solvers based on  Martin Reinecke committed Jan 23, 2018 156 157 158 159 160 161 162  - 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