affine

Module: affine

Inheritance diagram for regreg.affine:

digraph inheritance5aeff6cecc { rankdir=LR; size="8.0, 12.0"; "regreg.affine.AffineError" [URL="#regreg.affine.AffineError",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "regreg.affine.adjoint" [URL="#regreg.affine.adjoint",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Given an affine_transform, return a linear_transform"]; "regreg.affine.linear_transform" -> "regreg.affine.adjoint" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.affine_sum" [URL="#regreg.affine.affine_sum",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Creates the (weighted) sum of a list of affine_transforms"]; "regreg.affine.affine_transform" -> "regreg.affine.affine_sum" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.affine_transform" [URL="#regreg.affine.affine_transform",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "regreg.affine.aslinear" [URL="#regreg.affine.aslinear",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Return only linear part of affine transform"]; "regreg.affine.linear_transform" -> "regreg.affine.aslinear" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.composition" [URL="#regreg.affine.composition",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Composes a list of affine transforms, executing right to left"]; "regreg.affine.affine_transform" -> "regreg.affine.composition" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.hstack" [URL="#regreg.affine.hstack",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Stack several affine transforms horizontally together though"]; "regreg.affine.affine_transform" -> "regreg.affine.hstack" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.identity" [URL="#regreg.affine.identity",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Identity transform"]; "regreg.affine.affine_transform" -> "regreg.affine.identity" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.linear_transform" [URL="#regreg.affine.linear_transform",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="A linear transform is an affine transform with no affine offset"]; "regreg.affine.affine_transform" -> "regreg.affine.linear_transform" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.normalize" [URL="#regreg.affine.normalize",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Normalize column by means and possibly scale. Could make"]; "regreg.affine.affine_transform" -> "regreg.affine.normalize" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.posneg" [URL="#regreg.affine.posneg",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "regreg.affine.affine_transform" -> "regreg.affine.posneg" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.product" [URL="#regreg.affine.product",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Create a transform that maps the product of the inputs"]; "regreg.affine.affine_transform" -> "regreg.affine.product" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.reshape" [URL="#regreg.affine.reshape",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Reshape the output of an affine transform."]; "regreg.affine.linear_transform" -> "regreg.affine.reshape" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.residual" [URL="#regreg.affine.residual",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Compute the residual from an affine transform."]; "regreg.affine.affine_transform" -> "regreg.affine.residual" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.scalar_multiply" [URL="#regreg.affine.scalar_multiply",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top"]; "regreg.affine.affine_transform" -> "regreg.affine.scalar_multiply" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.selector" [URL="#regreg.affine.selector",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Apply an affine transform after applying an"]; "regreg.affine.linear_transform" -> "regreg.affine.selector" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.tensorize" [URL="#regreg.affine.tensorize",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Given an affine_transform, return a linear_transform"]; "regreg.affine.affine_transform" -> "regreg.affine.tensorize" [arrowsize=0.5,style="setlinewidth(0.5)"]; "regreg.affine.vstack" [URL="#regreg.affine.vstack",fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5)",target="_top",tooltip="Stack several affine transforms vertically together though"]; "regreg.affine.affine_transform" -> "regreg.affine.vstack" [arrowsize=0.5,style="setlinewidth(0.5)"]; }

Classes

AffineError

class regreg.affine.AffineError

Bases: Exception

__init__($self, /, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

adjoint

class regreg.affine.adjoint(transform)

Bases: regreg.affine.linear_transform

Given an affine_transform, return a linear_transform that is the adjoint of its linear part.

__init__(transform)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

affine_sum

class regreg.affine.affine_sum(transforms, weights=None)

Bases: regreg.affine.affine_transform

Creates the (weighted) sum of a list of affine_transforms

__init__(transforms, weights=None)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

affine_transform

class regreg.affine.affine_transform(linear_operator, affine_offset, diag=False, input_shape=None)

Bases: object

__init__(linear_operator, affine_offset, diag=False, input_shape=None)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

aslinear

class regreg.affine.aslinear(transform)

Bases: regreg.affine.linear_transform

Return only linear part of affine transform

__init__(transform)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

composition

class regreg.affine.composition(*transforms)

Bases: regreg.affine.affine_transform

Composes a list of affine transforms, executing right to left

__init__(*transforms)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

hstack

class regreg.affine.hstack(transforms)

Bases: regreg.affine.affine_transform

Stack several affine transforms horizontally together though not necessarily as a big matrix.

__init__(transforms)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

identity

class regreg.affine.identity(input_shape)

Bases: regreg.affine.affine_transform

Identity transform

__init__(input_shape)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

linear_transform

class regreg.affine.linear_transform(linear_operator, diag=False, input_shape=None)

Bases: regreg.affine.affine_transform

A linear transform is an affine transform with no affine offset

__init__(linear_operator, diag=False, input_shape=None)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

normalize

class regreg.affine.normalize(M, center=True, scale=True, value=1, inplace=False, intercept_column=None)

Bases: regreg.affine.affine_transform

Normalize column by means and possibly scale. Could make a class for row normalization to.

Columns are normalized to have std equal to value.

__init__(M, center=True, scale=True, value=1, inplace=False, intercept_column=None)
Parameters

M : ndarray or scipy.sparse

The matrix to be normalized. If an ndarray and inplace=True, then the values of M are modified in place. Sparse matrices are not modified in place.

center : bool

Center the columns?

scale : bool

Scale the columns?

value : float

Set the std of the columns to be value.

inplace : bool

If sensible, modify values in place. For a sparse matrix, this will raise an exception if True and center==True.

intercept_column : [int,None]

Which column is the intercept if any? This column is not centered or scaled.

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
normalized_array()
property shape
slice_columns(index_obj)
Parameters

index_obj: slice, list, np.bool

An object on which to index the columns of self.M. Must be a slice object or list so scipy.sparse matrices can be sliced.

Returns

n : normalize

A transform which agrees with self having zeroed out all coefficients not captured by index_obj.

Notes

This method does not check whether or not self.intercept_column is None so it must be set by hand on the returned instance.

Examples

>>> from regreg.affine import normalize
>>> X = np.array([1.2,3.4,5.6,7.8,1.3,4.5,5.6,7.8,1.1,3.4])
>>> D = np.identity(X.shape[0]) - np.diag(np.ones(X.shape[0]-1),1)
>>> nD = normalize(D)
>>> X_sliced = X.copy()
>>> X_sliced[:4] = 0; X_sliced[6:] = 0
>>> expected = [0, 0, 0, -2.906888, -7.155417, 10.06230, 0, 0, 0, 0]
>>> np.allclose(nD.linear_map(X_sliced), expected)
True
>>> nD_slice = nD.slice_columns(slice(4,6))
>>> np.allclose(nD_slice.linear_map(X[slice(4,6)]), expected)
True

posneg

class regreg.affine.posneg(linear_transform)

Bases: regreg.affine.affine_transform

__init__(linear_transform)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

product

class regreg.affine.product(transforms)

Bases: regreg.affine.affine_transform

Create a transform that maps the product of the inputs to the product of the outputs.

__init__(transforms)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

reshape

class regreg.affine.reshape(input_shape, output_shape)

Bases: regreg.affine.linear_transform

Reshape the output of an affine transform.

__init__(input_shape, output_shape)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

residual

class regreg.affine.residual(transform)

Bases: regreg.affine.affine_transform

Compute the residual from an affine transform.

__init__(transform)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

scalar_multiply

class regreg.affine.scalar_multiply(atransform, scalar)

Bases: regreg.affine.affine_transform

__init__(atransform, scalar)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

selector

class regreg.affine.selector(index_obj, initial_shape, affine_transform=None)

Bases: regreg.affine.linear_transform

Apply an affine transform after applying an indexing operation to the array.

>>> from regreg.affine import selector, affine_transform
>>> X = np.arange(30).reshape((6,5))
>>> offset = np.arange(6)
>>> transform = affine_transform(X, offset)
>>> apply_to_first5 = selector(slice(0,5), (7,), transform)
>>> apply_to_first5.linear_map(np.arange(7))
array([ 30,  80, 130, 180, 230, 280])
>>> np.dot(X, np.arange(5))
array([ 30,  80, 130, 180, 230, 280])
>>> apply_to_first5.affine_map(np.arange(7))
array([ 30,  81, 132, 183, 234, 285])
>>> np.dot(X, np.arange(5)) + offset
array([ 30,  81, 132, 183, 234, 285])
>>> result = np.array([275.,  290.,  305.,  320.,  335.,    0.,    0.])
>>> np.testing.assert_allclose(result, apply_to_first5.adjoint_map(np.arange(6)))
__init__(index_obj, initial_shape, affine_transform=None)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

tensorize

class regreg.affine.tensorize(transform, q)

Bases: regreg.affine.affine_transform

Given an affine_transform, return a linear_transform that expects q copies of something with transform’s input_shape.

This class effectively makes explicit that a transform may expect a matrix rather than a single vector.

__init__(transform, q)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(x)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

vstack

class regreg.affine.vstack(transforms)

Bases: regreg.affine.affine_transform

Stack several affine transforms vertically together though not necessarily as a big matrix.

__init__(transforms)

Create affine transform

Parameters

linear_operator : None or ndarray or sparse array or affine_transform

Linear part of affine transform implemented as array or as affine_transform. None results in no linear component.

affine_offset : None or ndarray

offset component of affine. Only one of linear_operator and affine_offset can be None, because we need an input array to define the shape of the transform.

diag : {False, True}, optional

If True, interpret 1D linear_operator as the main diagonal of the a diagonal array, so that linear_operator = np.diag(linear_operator)

property T
adjoint_map(u)

Apply transpose of linear component to u

Return \(D^Tu\)

Parameters

u : ndarray

array to which to apply transposed linear part of transform. Can be 1D or 2D array

copy : {True, False}, optional

If True, in situations where return is identical to u, ensure returned value is a copy.

Returns

DTu : ndarray

u transformed with transpose of linear component

Notes

This routine is currently a matrix multiplication, but could also call FFTs if D is a DFT matrix, in a subclass.

affine_map(x)

Apply linear and affine offset to x

Return \(Dx+\alpha\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

copy : {True, False}, optional

If True, in situations where return is identical to x, ensure returned value is a copy.

Returns

Dx_a : ndarray

x transformed with linear and offset components

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

dot(x)

Apply linear part of transform to x. Returns self.linear_map(x) unless x is a transform, in which case it returns the composition.

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

linear_map(x)

Apply linear part of transform to x

Return \(Dx\)

Parameters

x : ndarray

array to which to apply transform. Can be 1D or 2D

Returns

Dx : ndarray

x transformed with linear component

Notes

This routine is subclassed in affine_atom as a matrix multiplications, but could also call FFTs if D is a DFT matrix, in a subclass.

property ndim
property shape

Functions

regreg.affine.astransform(X)

If X is an affine_transform, return X, else try to cast it as an affine_transform

regreg.affine.broadcast_first(a, b, op)

apply binary operation op, broadcast a over axis 1 if necessary

Parameters

a : ndarray

If a is 1D shape (N,), convert to shape (N,1) before appling op. This has the effect of making broadcasting happen over axis 1 rather than the default of axis 0.

b : ndarray

If a is 1D shape (P,), convert to shape (N,1) before appling op

op : callable

binary operation to apply to a, b

Returns

res : object

shape equal to b.shape

regreg.affine.power_L(transform, max_its=500, tol=1e-08, debug=False)

Approximate the largest singular value (squared) of the linear part of a transform using power iterations

TODO: should this be the largest singular value instead (i.e. not squared?)

regreg.affine.todense(transform)

Return a dense array representation of a transform – use carefully – it could be large.