smoothness_operator.py 2.41 KB
Newer Older
1

2
3
4
from nifty.spaces.power_space import PowerSpace
from nifty.operators.endomorphic_operator import EndomorphicOperator
from nifty.operators.laplace_operator import LaplaceOperator
5
6
7


class SmoothnessOperator(EndomorphicOperator):
Jakob Knollmueller's avatar
Jakob Knollmueller committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    """An operator measuring the smoothness on an irregular grid with respect to some scale.

    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.


    Parameters
    ----------
    sigma: float,
        Specifies the strength of the SmoothnessOperator
    logarithmic : boolean,
        Whether smoothness is calculated on a logarithmic scale or linear scale
        default : True
    """
26

27
    # ---Overwritten properties and methods---
28

29
    def __init__(self, domain, sigma, logarithmic=True, default_spaces=None):
30

31
        super(SmoothnessOperator, self).__init__(default_spaces=default_spaces)
32
33

        self._domain = self._parse_domain(domain)
34
        if len(self.domain) != 1:
35
            raise ValueError("The domain must contain exactly one PowerSpace.")
36

37
38
39
40
        if not isinstance(self.domain[0], PowerSpace):
            raise TypeError("The domain must contain exactly one PowerSpace.")

        if sigma <= 0:
41
42
43
44
            raise ValueError("ERROR: invalid sigma.")

        self._sigma = sigma

45
46
        self._laplace = LaplaceOperator(domain=self.domain,
                                        logarithmic=logarithmic)
47

48
    # ---Mandatory properties and methods---
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

    @property
    def target(self):
        return self._domain

    @property
    def domain(self):
        return self._domain

    @property
    def unitary(self):
        return False

    @property
    def symmetric(self):
        return False

    @property
    def self_adjoint(self):
        return False

70
    def _times(self, x, spaces):
71
        res = self._laplace.adjoint_times(self._laplace(x, spaces), spaces)
72
        return (1./self.sigma)**2*res
73
74
75
76
77
78

    # ---Added properties and methods---

    @property
    def sigma(self):
        return self._sigma