smoothness_operator.py 2.24 KB
 Martin Reinecke committed Oct 07, 2017 1 2 3 4 ``````from ..spaces.power_space import PowerSpace from .endomorphic_operator import EndomorphicOperator from .laplace_operator import LaplaceOperator from .. import Field, DomainTuple `````` Jakob Knollmueller committed May 19, 2017 5 6 7 `````` class SmoothnessOperator(EndomorphicOperator): `````` Theo Steininger committed Jul 12, 2017 8 9 `````` """An operator measuring the smoothness on an irregular grid with respect to some scale. `````` Jakob Knollmueller committed Jun 07, 2017 10 `````` `````` Theo Steininger committed Jul 12, 2017 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 committed Jun 07, 2017 19 20 21 22 `````` Parameters ---------- `````` Theo Steininger committed Jul 19, 2017 23 `````` strength: float, `````` Jakob Knollmueller committed Jun 07, 2017 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 """ `````` Jakob Knollmueller committed May 19, 2017 29 `````` `````` Theo Steininger committed Jul 10, 2017 30 `````` # ---Overwritten properties and methods--- `````` Jakob Knollmueller committed May 19, 2017 31 `````` `````` Martin Reinecke committed Sep 25, 2017 32 33 34 35 `````` def __init__(self, domain, strength=1., logarithmic=True, space=None): super(SmoothnessOperator, self).__init__() self._laplace = LaplaceOperator(domain, logarithmic=logarithmic, space=space) `````` Theo Steininger committed Jul 10, 2017 36 `````` `````` Theo Steininger committed Jul 12, 2017 37 `````` if strength <= 0: `````` Jakob Knollmueller committed May 19, 2017 38 `````` raise ValueError("ERROR: invalid sigma.") `````` Theo Steininger committed Jul 12, 2017 39 `````` self._strength = strength `````` Jakob Knollmueller committed May 19, 2017 40 `````` `````` Theo Steininger committed Jul 10, 2017 41 `````` # ---Mandatory properties and methods--- `````` Jakob Knollmueller committed May 19, 2017 42 43 44 `````` @property def domain(self): `````` Martin Reinecke committed Sep 25, 2017 45 `````` return self._laplace._domain `````` Jakob Knollmueller committed May 19, 2017 46 47 48 49 50 51 52 53 54 55 56 57 58 `````` @property def unitary(self): return False @property def symmetric(self): return False @property def self_adjoint(self): return False `````` Martin Reinecke committed Sep 25, 2017 59 `````` def _times(self, x): `````` Theo Steininger committed Jul 12, 2017 60 `````` if self._strength != 0: `````` Martin Reinecke committed Sep 25, 2017 61 `````` result = self._laplace.adjoint_times(self._laplace(x)) `````` Theo Steininger committed Jul 12, 2017 62 63 `````` result *= self._strength**2 else: `````` Martin Reinecke committed Sep 05, 2017 64 `````` result = Field(x.domain, 0., x.dtype) `````` Theo Steininger committed Jul 12, 2017 65 `````` return result `````` Theo Steininger committed Jul 10, 2017 66 67 68 `````` # ---Added properties and methods--- `````` Theo Steininger committed Jul 19, 2017 69 70 71 72 `````` @property def logarithmic(self): return self._laplace.logarithmic `````` Theo Steininger committed Jul 10, 2017 73 `````` @property `````` Theo Steininger committed Jul 12, 2017 74 75 `````` def strength(self): return self._strength``````