Commit e77963eb authored by Martin Reinecke's avatar Martin Reinecke
Browse files

Merge branch 'master' into improve_readme

parents 13c82087 7b445aed
Pipeline #12462 passed with stage
in 4 minutes and 57 seconds
......@@ -28,6 +28,10 @@ class ComposedOperator(LinearOperator):
----------
operators : tuple of NIFTy Operators
The tuple of LinearOperators.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
......@@ -35,6 +39,8 @@ class ComposedOperator(LinearOperator):
The NIFTy.space in which the operator is defined.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The NIFTy.space in which the outcome of the operator lives
unitary : boolean
Indicates whether the Operator is unitary or not.
Raises
------
......
......@@ -50,9 +50,21 @@ class DiagonalOperator(EndomorphicOperator):
setting the prober distribution_strategy of the
diagonal (default : None). In case diagonal is d2o-object or Field,
their distribution_strategy is used as a fallback.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
distribution_strategy : string
Defines the distribution_strategy of the distributed_data_object
in which the diagonal entries are stored in.
......
......@@ -30,7 +30,9 @@ class EndomorphicOperator(LinearOperator):
Parameters
----------
#TODO: Copy Parameters from LinearOperator
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
......@@ -39,6 +41,8 @@ class EndomorphicOperator(LinearOperator):
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
......
......@@ -33,9 +33,21 @@ class ProjectionOperator(EndomorphicOperator):
----------
projection_field : Field
Field on which the operator projects
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
Raises
------
......
......@@ -46,9 +46,21 @@ class HarmonicPropagatorOperator(InvertibleOperatorMixin, EndomorphicOperator):
(default:ConjugateGradient)
preconditioner : Field
numerical preconditioner to speed up convergence
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
Raises
------
......
......@@ -44,9 +44,21 @@ class PropagatorOperator(InvertibleOperatorMixin, EndomorphicOperator):
(default:ConjugateGradient)
preconditioner : Field
numerical preconditioner to speed up convergence
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
Raises
------
......
......@@ -23,10 +23,19 @@ class ResponseOperator(LinearOperator):
Defines the smoothing length of the operator for each space it lives on
exposure : list(np.float)
Defines the exposure of the operator for each space it lives on
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
Raises
------
......@@ -71,27 +80,22 @@ class ResponseOperator(LinearOperator):
shape_target = np.append(shape_target, self._domain[ii].shape)
self._target = self._parse_domain(FieldArray(shape_target))
self._sigma = sigma
self._exposure = exposure
self._kernel = len(self._domain)*[None]
for ii in xrange(len(self._kernel)):
self._kernel[ii] = SmoothingOperator(self._domain[ii],
sigma=self._sigma[ii])
self._composed_kernel = ComposedOperator(self._kernel)
self._exposure_op = len(self._domain)*[None]
if len(self._exposure_op) != len(self._kernel):
raise ValueError("Definition of kernel and exposure do not suit "
"each other")
else:
for ii in xrange(len(self._exposure_op)):
self._exposure_op[ii] = DiagonalOperator(
self._domain[ii],
diagonal=self._exposure[ii])
self._composed_exposure = ComposedOperator(self._exposure_op)
kernel_smoothing = len(self._domain)*[None]
kernel_exposure = len(self._domain)*[None]
if len(sigma)!= len(exposure):
raise ValueError("Length of smoothing kernel and length of"
"exposure do not match")
for ii in xrange(len(kernel_smoothing)):
kernel_smoothing[ii] = SmoothingOperator(self._domain[ii],
sigma=sigma[ii])
kernel_exposure[ii] = DiagonalOperator(self._domain[ii],
diagonal=exposure[ii])
self._composed_kernel = ComposedOperator(kernel_smoothing)
self._composed_exposure = ComposedOperator(kernel_exposure)
@property
def domain(self):
......
......@@ -35,15 +35,28 @@ class SmoothingOperator(EndomorphicOperator):
Parameters
----------
domain : tuple of DomainObjects, i.e. Spaces and FieldTypes
The Space on which the operator acts
domain : DomainObject, i.e. Space or FieldType
The Space on which the operator acts. The SmoothingOperator
can only live on one space or FieldType
sigma : float
Sets the length of the Gaussian convolution kernel
log_distances : boolean
States whether the convolution happens on the logarithmic grid or not.
default_spaces : tuple of ints *optional*
Defines on which space(s) of a given field the Operator acts by
default (default: None)
Attributes
----------
domain : DomainObject, i.e. Space or FieldType
The domain on which the Operator's input Field lives.
target : tuple of DomainObjects, i.e. Spaces and FieldTypes
The domain in which the outcome of the operator lives. As the Operator
is endomorphic this is the same as its domain.
unitary : boolean
Indicates whether the Operator is unitary or not.
self_adjoint : boolean
Indicates whether the operator is self_adjoint or not.
sigma : float
Sets the length of the Gaussian convolution kernel
log_distances : boolean
......
import unittest
from numpy.testing import assert_equal,\
assert_allclose,\
assert_approx_equal
from nifty import Field,\
DiagonalOperator,\
ComposedOperator
from test.common import generate_spaces
from itertools import product
from test.common import expand
class ComposedOperator_Tests(unittest.TestCase):
spaces = generate_spaces()
@expand(product(spaces, spaces))
def test_property(self, space1, space2):
rand1 = Field.from_random('normal', domain=space1)
rand2 = Field.from_random('normal', domain=space2)
op1 = DiagonalOperator(space1, diagonal=rand1)
op2 = DiagonalOperator(space2, diagonal=rand2)
op = ComposedOperator((op1, op2))
if op.domain != (op1.domain[0], op2.domain[0]):
raise TypeError
if op.unitary != False:
raise ValueError
@expand(product(spaces,spaces))
def test_times_adjoint_times(self, space1, space2):
diag1 = Field.from_random('normal', domain=space1)
diag2 = Field.from_random('normal', domain=space2)
op1 = DiagonalOperator(space1, diagonal=diag1)
op2 = DiagonalOperator(space2, diagonal=diag2)
op = ComposedOperator((op1, op2))
rand1 = Field.from_random('normal', domain=(space1,space2))
rand2 = Field.from_random('normal', domain=(space1,space2))
tt1 = rand2.dot(op.times(rand1))
tt2 = rand1.dot(op.adjoint_times(rand2))
assert_approx_equal(tt1, tt2)
@expand(product(spaces, spaces))
def test_times_inverse_times(self, space1, space2):
diag1 = Field.from_random('normal', domain=space1)
diag2 = Field.from_random('normal', domain=space2)
op1 = DiagonalOperator(space1, diagonal=diag1)
op2 = DiagonalOperator(space2, diagonal=diag2)
op = ComposedOperator((op1, op2))
rand1 = Field.from_random('normal', domain=(space1, space2))
tt1 = op.inverse_times(op.times(rand1))
assert_allclose(tt1.val.get_full_data(),
rand1.val.get_full_data())
import unittest
from numpy.testing import assert_approx_equal
from nifty import Field,\
RGSpace,\
ResponseOperator
from itertools import product
from test.common import expand
class ResponseOperator_Tests(unittest.TestCase):
spaces = [RGSpace(100)]
@expand(product(spaces, [0., 5., 1.], [0., 1., .33] ))
def test_property(self, space, sigma, exposure):
op = ResponseOperator(space, sigma=[sigma],
exposure=[exposure])
if op.domain[0] != space:
raise TypeError
if op.unitary != False:
raise ValueError
@expand(product(spaces, [0., 5., 1.], [0., 1., .33] ))
def test_times_adjoint_times(self, space, sigma, exposure):
op = ResponseOperator(space, sigma=[sigma],
exposure=[exposure])
rand1 = Field.from_random('normal', domain=space)
rand2 = Field.from_random('normal', domain=op.target[0])
tt1 = rand2.dot(op.times(rand1))
tt2 = rand1.dot(op.adjoint_times(rand2))
assert_approx_equal(tt1, tt2)
import unittest
from numpy.testing import assert_equal,\
assert_allclose,\
assert_approx_equal
from nifty import Field,\
RGSpace,\
PowerSpace,\
SmoothingOperator
from itertools import product
from test.common import expand
class SmoothingOperator_Tests(unittest.TestCase):
spaces = [RGSpace(100)]
@expand(product(spaces, [0., .5, 5.], [True, False]))
def test_property(self, space, sigma, log_distances):
op = SmoothingOperator(space, sigma=sigma,
log_distances=log_distances)
if op.domain[0] != space:
raise TypeError
if op.unitary != False:
raise ValueError
if op.self_adjoint != True:
raise ValueError
if op.sigma != sigma:
raise ValueError
if op.log_distances != log_distances:
raise ValueError
@expand(product(spaces, [0., .5, 5.], [True, False]))
def test_adjoint_times(self, space, sigma, log_distances):
op = SmoothingOperator(space, sigma=sigma,
log_distances=log_distances)
rand1 = Field.from_random('normal', domain=space)
rand2 = Field.from_random('normal', domain=space)
tt1 = rand1.dot(op.times(rand2))
tt2 = rand2.dot(op.adjoint_times(rand1))
assert_approx_equal(tt1, tt2)
@expand(product(spaces, [0., .5, 5.], [False]))
def test_times(self, space, sigma, log_distances):
op = SmoothingOperator(space, sigma=sigma,
log_distances=log_distances)
rand1 = Field(space, val=0.)
rand1.val[0] = 1.
tt1 = op.times(rand1)
assert_approx_equal(1, tt1.sum())
@expand(product(spaces, [0., .5, 5.], [True, False]))
def test_inverse_adjoint_times(self, space, sigma, log_distances):
op = SmoothingOperator(space, sigma=sigma,
log_distances=log_distances)
rand1 = Field.from_random('normal', domain=space)
rand2 = Field.from_random('normal', domain=space)
tt1 = rand1.dot(op.inverse_times(rand2))
tt2 = rand2.dot(op.inverse_adjoint_times(rand1))
assert_approx_equal(tt1, tt2)
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