|
| 1 | +.. _functional_in_depth: |
| 2 | + |
| 3 | +##################### |
| 4 | +Functional |
| 5 | +##################### |
| 6 | + |
| 7 | +A *functional* is an operator ``f`` that maps from some vector space ``X`` to the field of scalars ``F`` associated with the vector space: |
| 8 | + |
| 9 | +.. math:: |
| 10 | + |
| 11 | + f : X \to F. |
| 12 | +
|
| 13 | +In the ODL solver package, functionals are implemented in the `Functional` class, a subclass to `Operator`. |
| 14 | + |
| 15 | +From a mathematical presepective, the above is a valide definition of a functional. However, since the purpose of these functionals are primarely to be used for solving optimization problems, the following assumptions are made: |
| 16 | + |
| 17 | + * the vector space ``X`` is a Hilbert space. |
| 18 | + * the field of scalars ``F`` are the real numbers. |
| 19 | + |
| 20 | +It is possible to use the class without fulfilling these assumtptions, however in this case some of the mathematical results might not hold. |
| 21 | + |
| 22 | + |
| 23 | +Implementation of functionals |
| 24 | +============================= |
| 25 | + |
| 26 | +To define your own functional, you start by writing:: |
| 27 | + |
| 28 | + class MyFunctional(odl.solvers.Functional): |
| 29 | + ... |
| 30 | + |
| 31 | +Since `Functional` is a subclass of `Operator`, it has the *abstract method* ``domain`` which need to be explicitly overridden by any subclass. |
| 32 | + |
| 33 | +``domain``: `Set` |
| 34 | + The domain of this functional, i.e., the set of elements to which this functional can be applied. |
| 35 | + |
| 36 | +Moreover, there are several optional parameters associated with a functional. These are |
| 37 | + |
| 38 | +``linear`` : `bool`, optional |
| 39 | + If `True`, the functional is considered as linear. In this case, ``domain`` and ``range`` have to be instances of `LinearSpace`, or `Field`. |
| 40 | + Default: ``False`` |
| 41 | +smooth : `bool`, optional |
| 42 | + If `True`, assume that the functional is continuously differentiable. |
| 43 | + Default: ``False`` |
| 44 | +concave : `bool`, optional |
| 45 | + If `True`, assume that the functional is concave. |
| 46 | + Default: ``False`` |
| 47 | +convex : `bool`, optional |
| 48 | + If `True`, assume that the functional is convex. |
| 49 | + Default: ``False`` |
| 50 | +grad_lipschitz : 'float', optional |
| 51 | + The Lipschitz constant of the gradient. |
| 52 | + Default: infinity |
| 53 | + |
| 54 | +A functional also has a number of optional methods and properties associated with it. The default value of these are all to raise a `NotImplemetedError`. The properties are: |
| 55 | + |
| 56 | + * ``gradient``. This returns the gradient operator of the functional, i.e., the operator that corresponds to the mapping |
| 57 | + |
| 58 | +.. math:: |
| 59 | +
|
| 60 | + x \\to \\nabla f(x) |
| 61 | +
|
| 62 | +where :math:`\\nabla f(x)` is the element used to evaluate derivatives in a direction :math:`d` by :math:`\\langle \\nabla f(x), d \\rangle`. |
| 63 | + * ``conjugate_functional``. This is the convex conjugate functional, also known as the Legendre transform or Fenchel conjugate. It is defined as |
| 64 | + |
| 65 | +.. math:: |
| 66 | +
|
| 67 | + f^*(x^*) = \sup_{x \in X} \{ \langle x^*,x \rangle - f(x) \}. |
| 68 | +
|
| 69 | +For general linear spaces :math:`X`, :math:`x^* \in X^*` the (continuous/normed) dual space of :math:`X`, i.e., the space of all continuous linear functionals defined on :math:`X`. Then :math:`\langle x^*,x \rangle` is the "dual pairing", i.e., the evaluation of the linear functional :math:`x^*` in the point :math:`x`. However, Hilbert spaces are self-dual, meaning :math:`X^* = X`, and :math:`\langle x^*,x \rangle` is the inner product. |
| 70 | + |
| 71 | +The optional method is |
| 72 | + |
| 73 | + * ``proximal(sigma)``. This returns the proximal operator of the functional, where ``sigma`` is a nonnegative step-size like parameter. The proximal operator is defined as |
| 74 | + |
| 75 | +.. math:: |
| 76 | +
|
| 77 | + \text{prox}_{\sigma f}(x) = \text{arg min}_{y \in X} \{ f(y) + \frac{1}{2\sigma} \|y - x\|_2^2 \} |
| 78 | +
|
| 79 | +The `Functional` class also contains two default implementations of two help functions: |
| 80 | + |
| 81 | +* ``derivative(point)``. Given an implementation of the gradient, this method return the (directional) derivative operator in ``point``. This is the linear operator |
| 82 | + |
| 83 | +.. math:: |
| 84 | + x \to \langle x, \nabla f(point) \rangle, |
| 85 | +
|
| 86 | +where :math:`\nabla f(point)` is the gradient of the functional in the point :math:`point`. |
| 87 | +* ``translate(shift)``. Give a functional :math:`f(.)`, this method creates the functional :math:`f(. - shift)` |
| 88 | + |
| 89 | + |
| 90 | +Functional arithmetics |
| 91 | +====================== |
| 92 | +It is common in applications to perform arithmetic operations with functionals, for example adding two functionals :math:`f` and :math:`g` |
| 93 | + |
| 94 | +.. math:: |
| 95 | + [f+g](x) = f(x) + g(x), |
| 96 | +
|
| 97 | +or multiplication of a functional by a scalar |
| 98 | + |
| 99 | +.. math:: |
| 100 | + [\alpha f](x) = \alpha f (x). |
| 101 | +
|
| 102 | +Another example is translating a functional with a vecotr :math:`y` |
| 103 | + |
| 104 | +.. math:: |
| 105 | + f(x - y), |
| 106 | +
|
| 107 | +or given an `Operator` :math:`A` whose range is the same as the domain as the functional we also have composition |
| 108 | + |
| 109 | +.. math:: |
| 110 | + [f * A](x) = f(A(x)). |
| 111 | +
|
| 112 | +In some of these cases, properties and methods such as ``gradient``, ``convex_conjugate`` and ``proximal`` can be calculated automatically given a default implementation of the corresponding property in :math:`f`. |
| 113 | + |
| 114 | +All available functional arithmetic, including which properties and methods that automatically can be calculated, is shown below. ``f``, ``g`` represent `Functional`'s, and ``A`` an `Operator` whose range is the same as the domain as the functional. `` a`` is a scalar in the field of the domain of ``f`` and ``g``, and ``y`` is a vector in the domain of ``f`` and ``g``. |
| 115 | + |
| 116 | ++------------------+-----------------+-------------------------------------------------+ |
| 117 | +| Code | Meaning | Class | |
| 118 | ++==================+=================+=================================================+ |
| 119 | +| ``(f + g)(x)`` | ``f(x) + g(x)`` | `FunctionalSum` | |
| 120 | +| | | - Retains `gradient`. | |
| 121 | ++------------------+-----------------+-------------------------------------------------+ |
| 122 | +| ``(f + a)(x) | ``f(x) + a`` | `FunctionalScalarSum` | |
| 123 | +| | | - Retains all properties. | |
| 124 | ++------------------+-----------------+-------------------------------------------------+ |
| 125 | +| ``(f * A)(x)`` | ``f(A(x))`` | `FunctionalComp` | |
| 126 | +| | | - Retains gradient | |
| 127 | ++------------------+-----------------+-------------------------------------------------+ |
| 128 | +| ``(a * f)(x)`` | ``a * f(x)`` | `FunctionalLeftScalarMult` | |
| 129 | +| | | - Retains all properties, if ``a`` is positive. | |
| 130 | ++------------------+-----------------+-------------------------------------------------+ |
| 131 | +| ``(f * a)(x)`` | ``f(a * x)`` | `FunctionalRightScalarMult` | |
| 132 | +| | | - Retains all properties | |
| 133 | ++------------------+-----------------+-------------------------------------------------+ |
| 134 | +| ``(v * f)(x)`` | ``v * f(x)`` | `FunctionalLeftVectorMult` | |
| 135 | +| | | - Note that this is not a functional anymore. | |
| 136 | ++------------------+-----------------+-------------------------------------------------+ |
| 137 | +| ``(f * v)(x)`` | ``f(v * x)`` | `FunctionalRightVectorMult` | |
| 138 | +| | | - Retains gradient and convex conjugate. | |
| 139 | ++------------------+-----------------+-------------------------------------------------+ |
| 140 | +| ``f.translate(y) | ``f(. - y)`` | `TranslatedFunctional` | |
| 141 | +| | | - Retains all properties. | |
| 142 | ++------------------+-----------------+-------------------------------------------------+ |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
0 commit comments