Commit 5dcdcd7e authored by Martin Reinecke's avatar Martin Reinecke

sync DiagonalOperator with the one on th nightly branch

parent 2bc560a9
Pipeline #20080 passed with stage
in 4 minutes and 12 seconds
......@@ -72,7 +72,7 @@ if __name__ == "__main__":
R = AdjointFFTResponse(fft, Instrument)
noise = 1.
N = ift.DiagonalOperator(ift.Field.full(s_space, noise))
N = ift.DiagonalOperator(ift.Field.full(s_space, noise).weight(1))
n = ift.Field.from_random(domain=s_space,
random_type='normal',
std=np.sqrt(noise),
......
......@@ -37,7 +37,7 @@ if __name__ == "__main__":
# Setting up the noise covariance and drawing a random noise realization
ndiag = ift.Field.full(data_domain, mock_signal.var()/signal_to_noise)
N = ift.DiagonalOperator(ndiag)
N = ift.DiagonalOperator(ndiag.weight(1))
noise = ift.Field.from_random(domain=data_domain, random_type='normal',
std=mock_signal.std()/np.sqrt(signal_to_noise), mean=0)
data = R(ift.exp(mock_signal)) + noise #|\label{code:wf_mock_data}|
......
......@@ -60,7 +60,7 @@ if __name__ == "__main__":
diagonal = ift.power_synthesize_special(mock_power, spaces=(0, 1))**2
diagonal = diagonal.real
S = ift.DiagonalOperator(diagonal.weight(-1))
S = ift.DiagonalOperator(diagonal)
np.random.seed(10)
......@@ -83,7 +83,7 @@ if __name__ == "__main__":
# Setting up the noise covariance and drawing a random noise realization
ndiag = ift.Field.full(data_domain, mock_signal.var()/signal_to_noise)
N = ift.DiagonalOperator(ndiag)
N = ift.DiagonalOperator(ndiag.weight(1))
noise = ift.Field.from_random(domain=data_domain, random_type='normal',
std=mock_signal.std()/np.sqrt(signal_to_noise),
mean=0)
......
......@@ -36,7 +36,7 @@ if __name__ == "__main__":
# Setting up the noise covariance and drawing a random noise realization
ndiag = ift.Field.full(data_domain, mock_signal.var()/signal_to_noise)
N = ift.DiagonalOperator(ndiag)
N = ift.DiagonalOperator(ndiag.weight(1))
noise = ift.Field.from_random(domain=data_domain, random_type='normal',
std=mock_signal.std()/np.sqrt(signal_to_noise), mean=0)
data = R(mock_signal) + noise #|\label{code:wf_mock_data}|
......
......@@ -55,8 +55,9 @@ if __name__ == "__main__":
data_domain = R.target[0]
R_harmonic = ift.ComposedOperator([fft, R])
N = ift.DiagonalOperator(ift.Field.full(data_domain,
mock_signal.var()/signal_to_noise))
N = ift.DiagonalOperator(
ift.Field.full(data_domain,
mock_signal.var()/signal_to_noise).weight(1))
noise = ift.Field.from_random(
domain=data_domain, random_type='normal',
std=mock_signal.std()/np.sqrt(signal_to_noise), mean=0)
......
......@@ -58,13 +58,13 @@ if __name__ == "__main__":
# Instrument = ift.FFTSmoothingOperator(s_space, sigma=0.05)
diag = ift.Field.ones(s_space)
diag.val[20:80, 20:80] = 0
Instrument = ift.DiagonalOperator(diag.weight(-1))
Instrument = ift.DiagonalOperator(diag)
# Adding a harmonic transformation to the instrument
R = AdjointFFTResponse(fft, Instrument)
signal_to_noise = 1.
ndiag = ift.Field.full(s_space, ss.var()/signal_to_noise)
N = ift.DiagonalOperator(ndiag)
N = ift.DiagonalOperator(ndiag.weight(1))
n = ift.Field.from_random(domain=s_space,
random_type='normal',
std=ss.std()/np.sqrt(signal_to_noise),
......
......@@ -21,7 +21,7 @@ class CriticalPowerCurvature(EndomorphicOperator):
# ---Overwritten properties and methods---
def __init__(self, theta, T):
self.theta = DiagonalOperator(theta)
self.theta = DiagonalOperator(theta.weight(1))
self.T = T
super(CriticalPowerCurvature, self).__init__()
......
......@@ -34,7 +34,8 @@ class DiagonalOperator(EndomorphicOperator):
Parameters
----------
diagonal : Field
The diagonal entries of the operator.
The diagonal entries of the operator
(already containing volume factors).
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
If None, use the domain of "diagonal".
......@@ -52,11 +53,11 @@ class DiagonalOperator(EndomorphicOperator):
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
Indicates whether the operator is self-adjoint or not.
NOTE: the fields given to __init__ and returned from .diagonal() are
considered to be bare, i.e. during operator application, the colume factors
are applied explicitly.
considered to be non-bare, i.e. during operator application, no additional
volume factors are applied!
See Also
--------
......@@ -90,7 +91,7 @@ class DiagonalOperator(EndomorphicOperator):
if diagonal.domain[i] != self._domain[j]:
raise ValueError("domain mismatch")
self._diagonal = diagonal.weight(1)
self._diagonal = diagonal.copy()
self._self_adjoint = None
self._unitary = None
......@@ -114,7 +115,7 @@ class DiagonalOperator(EndomorphicOperator):
out : Field
The diagonal of the Operator.
"""
return self._diagonal.weight(-1)
return self._diagonal.copy()
@property
def domain(self):
......
......@@ -62,7 +62,7 @@ class ResponseOperator(LinearOperator):
space=spaces[x])
for x in range(nsigma)]
kernel_exposure = [DiagonalOperator(Field(self._domain[spaces[x]],
exposure[x]).weight(-1),
exposure[x]),
domain=self._domain,
spaces=(spaces[x],))
for x in range(nsigma)]
......
......@@ -254,7 +254,8 @@ def create_power_operator(domain, power_spectrum, dtype=None):
DiagonalOperator : An operator that implements the given power spectrum.
"""
return DiagonalOperator(create_power_field(domain, power_spectrum, dtype))
return DiagonalOperator(
create_power_field(domain, power_spectrum, dtype).weight(1))
def generate_posterior_sample(mean, covariance):
......@@ -284,10 +285,10 @@ def generate_posterior_sample(mean, covariance):
R = covariance.op.R
N = covariance.op.N
power = sqrt(power_analyze(S.diagonal().weight(1)))
power = sqrt(power_analyze(S.diagonal()))
mock_signal = power_synthesize(power, real_signal=True)
noise = N.diagonal()
noise = N.diagonal().weight(-1)
mock_noise = Field.from_random(random_type="normal", domain=N.domain,
dtype=noise.dtype.type)
......
......@@ -101,9 +101,9 @@ class Test_Functionality(unittest.TestCase):
fp2 = Field(p2, val=spec2(p2.k_lengths))
S_1 = create_power_field(space1, lambda x: np.sqrt(spec1(x)))
S_1 = DiagonalOperator(S_1.weight(-1), domain=fulldomain, spaces=0)
S_1 = DiagonalOperator(S_1, domain=fulldomain, spaces=0)
S_2 = create_power_field(space2, lambda x: np.sqrt(spec2(x)))
S_2 = DiagonalOperator(S_2.weight(-1), domain=fulldomain, spaces=1)
S_2 = DiagonalOperator(S_2, domain=fulldomain, spaces=1)
samples = 500
ps1 = 0.
......
......@@ -21,7 +21,7 @@ class Test_Minimizers(unittest.TestCase):
starting_point = ift.Field.from_random('normal', domain=space)*10
covariance_diagonal = ift.Field.from_random(
'uniform', domain=space) + 0.5
covariance = ift.DiagonalOperator(covariance_diagonal.weight(-1))
covariance = ift.DiagonalOperator(covariance_diagonal)
required_result = ift.Field.ones(space, dtype=np.float64)
IC = ift.GradientNormController(tol_abs_gradnorm=1e-5)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment