diff --git a/nifty/minimization/conjugate_gradient.py b/nifty/minimization/conjugate_gradient.py index 00a12efa9be1f9ce57b899c3c9b37572d0a1ed4e..d7caccdd03b11b8a5fb4a5dcabbefe3ac1ca1b80 100644 --- a/nifty/minimization/conjugate_gradient.py +++ b/nifty/minimization/conjugate_gradient.py @@ -70,7 +70,7 @@ class ConjugateGradient(Loggable, object): References ---------- - Thomas V. Mikosch et al., "Numerical Optimization", Second Edition, + Jorge Nocedal & Stephen Wright, "Numerical Optimization", Second Edition, 2006, Springer-Verlag New York """ diff --git a/nifty/operators/diagonal_operator/diagonal_operator.py b/nifty/operators/diagonal_operator/diagonal_operator.py index 77f843fc2736aadda966116e66f1608c1cc6fbf2..f45cac9cb7e75324a19591e45f6b3324a244adf7 100644 --- a/nifty/operators/diagonal_operator/diagonal_operator.py +++ b/nifty/operators/diagonal_operator/diagonal_operator.py @@ -132,127 +132,6 @@ class DiagonalOperator(EndomorphicOperator): return self._times_helper(x, spaces, operation=lambda z: z.adjoint().__rdiv__) - def diagonal(self, bare=False, copy=True): - """ Returns the diagonal of the Operator. - - Parameters - ---------- - bare : boolean - Whether the returned Field values should be bare or not. - copy : boolean - Whether the returned Field should be copied or not. - - Returns - ------- - out : Field - The diagonal of the Operator. - - """ - if bare: - diagonal = self._diagonal.weight(power=-1) - elif copy: - diagonal = self._diagonal.copy() - else: - diagonal = self._diagonal - return diagonal - - def inverse_diagonal(self, bare=False): - """ Returns the inverse-diagonal of the operator. - - Parameters - ---------- - bare : boolean - Whether the returned Field values should be bare or not. - - Returns - ------- - out : Field - The inverse of the diagonal of the Operator. - - """ - return 1./self.diagonal(bare=bare, copy=False) - - def trace(self, bare=False): - """ Returns the trace the operator. - - Parameters - ---------- - bare : boolean - Whether the returned Field values should be bare or not. - - Returns - ------- - out : scalar - The trace of the Operator. - - """ - return self.diagonal(bare=bare, copy=False).sum() - - def inverse_trace(self, bare=False): - """ Returns the inverse-trace of the operator. - - Parameters - ---------- - bare : boolean - Whether the returned Field values should be bare or not. - - Returns - ------- - out : scalar - The inverse of the trace of the Operator. - - """ - return self.inverse_diagonal(bare=bare).sum() - - def trace_log(self): - """ Returns the trave-log of the operator. - - Returns - ------- - out : scalar - the trace of the logarithm of the Operator. - - """ - log_diagonal = nifty_log(self.diagonal(copy=False)) - return log_diagonal.sum() - - def determinant(self): - """ Returns the determinant of the operator. - - Returns - ------- - out : scalar - out : scalar - the determinant of the Operator - - """ - - return self.diagonal(copy=False).val.prod() - - def inverse_determinant(self): - """ Returns the inverse-determinant of the operator. - - Returns - ------- - out : scalar - the inverse-determinant of the Operator - - """ - - return 1/self.determinant() - - def log_determinant(self): - """ Returns the log-eterminant of the operator. - - Returns - ------- - out : scalar - the log-determinant of the Operator - - """ - - return np.log(self.determinant()) - # ---Mandatory properties and methods--- @property diff --git a/nifty/operators/response_operator/response_operator.py b/nifty/operators/response_operator/response_operator.py index 0e25e4282547524304968319bfad3e08c438e15b..75361469d01b78e297ea27e5e76d8dd7585df9b6 100644 --- a/nifty/operators/response_operator/response_operator.py +++ b/nifty/operators/response_operator/response_operator.py @@ -85,7 +85,7 @@ class ResponseOperator(LinearOperator): kernel_smoothing = len(self._domain)*[None] kernel_exposure = len(self._domain)*[None] - if len(sigma)!= len(exposure): + if len(sigma) != len(exposure): raise ValueError("Length of smoothing kernel and length of" "exposure do not match") diff --git a/test/test_operators/test_diagonal_operator.py b/test/test_operators/test_diagonal_operator.py index ef953fa0602b50f923d6566fbebe6205f3f8e44c..9b8bf86ced8c40daa82bda250bc88507147b00c1 100644 --- a/test/test_operators/test_diagonal_operator.py +++ b/test/test_operators/test_diagonal_operator.py @@ -76,61 +76,3 @@ class DiagonalOperator_Tests(unittest.TestCase): D = DiagonalOperator(space, diagonal=diag, bare=bare, copy=copy) tt = D.adjoint_inverse_times(rand1) assert_equal(tt.domain[0], space) - - @expand(product(spaces, [True, False])) - def test_diagonal(self, space, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, copy=copy) - diag_op = D.diagonal() - assert_allclose(diag.val.get_full_data(), diag_op.val.get_full_data()) - - @expand(product(spaces, [True, False])) - def test_inverse(self, space, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, copy=copy) - diag_op = D.inverse_diagonal() - assert_allclose(1./diag.val.get_full_data(), diag_op.val.get_full_data()) - - @expand(product(spaces, [True, False])) - def test_trace(self, space, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, copy=copy) - trace_op = D.trace() - assert_allclose(trace_op, np.sum(diag.val.get_full_data())) - - @expand(product(spaces, [True, False])) - def test_inverse_trace(self, space, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, copy=copy) - trace_op = D.inverse_trace() - assert_allclose(trace_op, np.sum(1./diag.val.get_full_data())) - - @expand(product(spaces, [True, False])) - #MR FIXME: what if any diagonal element <=0? - def test_trace_log(self, space, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, copy=copy) - trace_log = D.trace_log() - assert_allclose(trace_log, np.sum(np.log(diag.val.get_full_data()))) - - @expand(product(spaces, [True, False])) - def test_determinant(self, space, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, copy=copy) - det = D.determinant() - assert_allclose(det, np.prod(diag.val.get_full_data())) - - @expand(product(spaces, [True, False], [True, False])) - def test_inverse_determinant(self, space, bare, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, bare=bare, copy=copy) - inv_det = D.inverse_determinant() - assert_allclose(inv_det, 1./D.determinant()) - - @expand(product(spaces, [True, False], [True, False])) - #MR FIXME: what if determinant <=0? - def test_log_determinant(self, space, bare, copy): - diag = Field.from_random('normal', domain=space) - D = DiagonalOperator(space, diagonal=diag, bare=bare, copy=copy) - log_det = D.log_determinant() - assert_allclose(log_det, np.log(D.determinant()))