smoothness_operator.py 1.94 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
from .endomorphic_operator import EndomorphicOperator
from .laplace_operator import LaplaceOperator
3
4
5


class SmoothnessOperator(EndomorphicOperator):
6
7
    """An operator measuring the smoothness on an irregular grid with respect
    to some scale.
Jakob Knollmueller's avatar
Jakob Knollmueller committed
8

9
10
11
12
13
14
15
16
    This operator applies the irregular LaplaceOperator and its adjoint to some
    Field over a PowerSpace which corresponds to its smoothness and weights the
    result with a scale parameter sigma. It is used in the smoothness prior
    terms of the CriticalPowerEnergy. For this purpose we use free boundary
    conditions in the LaplaceOperator, having no curvature at both ends. In
    addition the first entry is ignored as well, corresponding to the overall
    mean of the map. The mean is therefore not considered in the smoothness
    prior.
Jakob Knollmueller's avatar
Jakob Knollmueller committed
17
18
19
20


    Parameters
    ----------
21
    strength: float,
Jakob Knollmueller's avatar
Jakob Knollmueller committed
22
23
24
25
26
        Specifies the strength of the SmoothnessOperator
    logarithmic : boolean,
        Whether smoothness is calculated on a logarithmic scale or linear scale
        default : True
    """
27

28
29
    def __init__(self, domain, strength=1., logarithmic=True, space=None):
        super(SmoothnessOperator, self).__init__()
Martin Reinecke's avatar
Martin Reinecke committed
30
31
        self._laplace = LaplaceOperator(domain, logarithmic=logarithmic,
                                        space=space)
32

Martin Reinecke's avatar
Martin Reinecke committed
33
34
        if strength < 0:
            raise ValueError("ERROR: strength must be >=0.")
35
        self._strength = strength
36
37
38

    @property
    def domain(self):
39
        return self._laplace._domain
40
41
42
43
44
45
46
47
48

    @property
    def unitary(self):
        return False

    @property
    def self_adjoint(self):
        return False

49
    def _times(self, x):
Martin Reinecke's avatar
Martin Reinecke committed
50
51
        if self._strength == 0.:
            return x.zeros_like(x)
Martin Reinecke's avatar
Martin Reinecke committed
52
53
        result = self._laplace.adjoint_times(self._laplace(x))
        result *= self._strength**2
54
        return result
55

56
57
58
59
    @property
    def logarithmic(self):
        return self._laplace.logarithmic

60
    @property
61
62
    def strength(self):
        return self._strength