Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trivial operators - improve documentation #1960

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Wrappers/Python/cil/optimisation/operators/IdentityOperator.py
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@

class IdentityOperator(LinearOperator):

'''IdentityOperator: Id: X -> Y, Id(x) = x\in Y
r''' `IdentityOperator`: :math:`\mathrm{Id}: X \rightarrow Y`, :math:`\mathrm{Id}(x) = x`

X : gm_domain
Y : gm_range ( Default: Y = X )
:math:`X` : domain
:math:`Y` : range ( Default: :math:`Y = X` )

Parameters
----------
domain_geometry: CIL Geometry
domain of the operator
range_geometry: CIL Geometry, optional
range of the operator, default: same as domain
'''


Expand All @@ -42,7 +48,7 @@ def __init__(self, domain_geometry, range_geometry=None):

def direct(self,x,out=None):

'''Returns Id(x)'''
r'''Returns :math:`\mathrm{Id}(x)` '''

if out is None:
return x.copy()
Expand All @@ -52,7 +58,7 @@ def direct(self,x,out=None):

def adjoint(self,x, out=None):

'''Returns Id(x)'''
r'''Returns :math:`\mathrm{Id}(x)=x` '''


if out is None:
Expand All @@ -63,7 +69,7 @@ def adjoint(self,x, out=None):

def calculate_norm(self, **kwargs):

'''Evaluates operator norm of IdentityOperator'''
'''Evaluates operator norm of `IdentityOperator`'''

return 1.0

Expand All @@ -85,8 +91,10 @@ def sum_abs_col(self):

def is_orthogonal(self):
'''Returns if the operator is orthogonal

Returns
-------
`Bool`
Always returns `True` for `IdentityOperator`
'''
return True
45 changes: 37 additions & 8 deletions Wrappers/Python/cil/optimisation/operators/MatrixOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,39 @@
from cil.optimisation.operators import LinearOperator

class MatrixOperator(LinearOperator):
""" Matrix wrapped into a LinearOperator
r""" Matrix wrapped in a CIL Operator to be used in optimisation algorithms.

:param: a numpy matrix
Parameters
----------
A: a numpy matrix
The matrix to be wrapped into a CIL Operator

"""

def __init__(self,A):
'''creator

:param A: numpy ndarray representing a matrix
'''
"""Constructor"""
self.A = A
M_A, N_A = self.A.shape
domain_geometry = VectorGeometry(N_A, dtype=A.dtype)
range_geometry = VectorGeometry(M_A, dtype=A.dtype)
self.s1 = None # Largest singular value, initially unknown
super(MatrixOperator, self).__init__(domain_geometry=domain_geometry,
range_geometry=range_geometry)

def direct(self,x, out=None):

r"""Returns :math:`Ax`

Parameters
----------
x : DataContainer
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
Input data
out : DataContainer, optional
Output data, default is None
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
Returns
-------
DataContainer
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
:math:`Ax`
"""

if out is None:
tmp = self.range_geometry().allocate()
tmp.fill(numpy.dot(self.A,x.as_array()))
Expand All @@ -55,6 +67,21 @@ def direct(self,x, out=None):
return out

def adjoint(self,x, out=None):
r"""Returns :math:`A^{T}x`

Parameters
----------
x : DataContainer
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
Input data
out : DataContainer, optional
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
Output data, default is None

Returns
-------
DataContainer
lauramurgatroyd marked this conversation as resolved.
Show resolved Hide resolved
:math:`A^{T}x`
"""

if out is None:
tmp = self.domain_geometry().allocate()
tmp.fill(numpy.dot(self.A.transpose().conjugate(),x.as_array()))
Expand All @@ -64,4 +91,6 @@ def adjoint(self,x, out=None):
return out

def size(self):
r"""Returns the shape of the matrix
"""
return self.A.shape
24 changes: 15 additions & 9 deletions Wrappers/Python/cil/optimisation/operators/ZeroOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@
from cil.optimisation.operators import LinearOperator

class ZeroOperator(LinearOperator):
r'''ZeroOperator: O: X -> Y, maps any element of :math:`x\in X` into the zero element :math:`\in Y, O(x) = O_{Y}`
r''' `ZeroOperator`: :math:`\mathrm{O}: X \rightarrow Y`, maps any element of :math:`x\in X` into the zero element in the space :math:`Y`, so :math:`\mathrm{O}(x) = \mathrm{O}_{Y}`.

:param gm_domain: domain of the operator
:param gm_range: range of the operator, default: same as domain
Parameters
----------

domain_geometry: CIL Geometry
domain of the operator
range_geometry: CIL Geometry, optional
range of the operator, default: same as domain

Note:
Note
-----

.. math::
O^{*}: Y^{*} -> X^{*} \text{(Adjoint)}
< O(x), y > = < x, O^{*}(y) >
O^{*}: Y^{*} -> X^{*} \text{(Adjoint)} \quad \text{such that} \quad
\langle O(x), y \rangle = \langle x, O^{*}(y) \rangle
'''
def __init__(self, domain_geometry, range_geometry=None):
if range_geometry is None:
Expand All @@ -39,21 +45,21 @@ def __init__(self, domain_geometry, range_geometry=None):
range_geometry=range_geometry)

def direct(self,x,out=None):
'''Returns O(x)'''
r'''Returns :math:`\mathrm{O}(x)`'''
if out is None:
return self.range_geometry().allocate(value=0)
else:
out.fill(self.range_geometry().allocate(value=0))
return out

def adjoint(self,x, out=None):
'''Returns O^{*}(y)'''
r'''Returns :math:`\mathrm{O}^{*}(y)` '''
if out is None:
return self.domain_geometry().allocate(value=0)
else:
out.fill(self.domain_geometry().allocate(value=0))
return out

def calculate_norm(self, **kwargs):
'''Evaluates operator norm of ZeroOperator'''
r'''Evaluates operator norm of `ZeroOperator`'''
return 0
Loading