smoothness_operator.py 2.04 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
2
3
4
from ..spaces.power_space import PowerSpace
from .endomorphic_operator import EndomorphicOperator
from .laplace_operator import LaplaceOperator
from .. import Field, DomainTuple
5
6
7


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

11
12
13
14
15
16
17
18
    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
19
20
21
22


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

30
31
32
33
    def __init__(self, domain, strength=1., logarithmic=True, space=None):
        super(SmoothnessOperator, self).__init__()
        self._laplace = LaplaceOperator(domain,
                                        logarithmic=logarithmic, space=space)
34

35
        if strength <= 0:
36
            raise ValueError("ERROR: invalid sigma.")
37
        self._strength = strength
38
39
40

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

    @property
    def unitary(self):
        return False

    @property
    def self_adjoint(self):
        return False

51
    def _times(self, x):
52
        if self._strength != 0:
53
            result = self._laplace.adjoint_times(self._laplace(x))
54
55
            result *= self._strength**2
        else:
56
            result = Field.zeros_like(x)
57
        return result
58

59
60
61
62
    @property
    def logarithmic(self):
        return self._laplace.logarithmic

63
    @property
64
65
    def strength(self):
        return self._strength