ModeBasis

class hcipy.mode_basis.ModeBasis(transformation_matrix, grid=None)

Bases: object

A list of modes.

Parameters
transformation_matrixarray_like or list of array_like

The transformation matrix of the mode basis or a list of modes.

gridGrid or None

The grid on which the modes are defined.

Attributes Summary

is_dense

If the mode basis is dense.

is_sparse

If the mode basis is sparse.

orthogonalized

Get an orthogonalized version of this ModeBasis.

transformation_matrix

The transformation matrix of this mode basis.

Methods Summary

append(self, mode)

Append mode to this mode basis.

coefficients_for(self, b[, dampening_factor])

Calculate the coefficients on this mode basis in a least squares fashion.

extend(self, modes)

Extend the mode basis with modes.

linear_combination(self, coefficients)

Calculate a linear combination using this mode basis.

to_dense(self[, copy])

Convert the mode basis to a dense mode basis.

to_sparse(self[, copy])

Convert the mode basis to a sparse mode basis.

Attributes Documentation

is_dense

If the mode basis is dense.

is_sparse

If the mode basis is sparse.

orthogonalized

Get an orthogonalized version of this ModeBasis.

The resulting ModeBasis spans the same vector space, but each mode is orthogonal to all others. In general the resulting ModeBasis is dense, so no distinction is made between sparse and dense mode bases in this function. This function will always return a dense mode basis.

Returns
ModeBasis

A mode basis with orthogonalized modes.

Raises
NotImplementedError

If the mode basis is a mode basis containing non-scalar fields.

transformation_matrix

The transformation matrix of this mode basis.

Methods Documentation

append(self, mode)

Append mode to this mode basis.

Parameters
modearray_like or Field

The mode to add to the ModeBasis

coefficients_for(self, b, dampening_factor=0)

Calculate the coefficients on this mode basis in a least squares fashion.

The vector b is projection onto the mode basis in a least squares fashion. This means that the const function

\[J(c) = |b - A x|^2_2 + |\lambda x|^2_2\]

is minimized, where \(x\) are the coefficients, and \(\lambda\) is the dampening factor.

If this projection needs to be done repeatedly, you may be better off calculating the inverse of the transformation matrix directly and left-multiplying that with your vector, rather than using a least squares estimation every time.

Parameters
barray_like or Field

The vector for which to calculate the coefficients.

dampening_factorscalar

The Tikhonov dampening factor used for the least squares procedure.

Returns
array_like

The coefficients that correspond to the vector b.

extend(self, modes)

Extend the mode basis with modes.

Parameters
modeslist or array_like or ModeBasis

The modes to add to the ModeBasis.

linear_combination(self, coefficients)

Calculate a linear combination using this mode basis.

Parameters
coefficientsarray_like or list

The coefficients of the linear combinations.

Returns
array_like or Field

The calculated linear combination.

to_dense(self, copy=False)

Convert the mode basis to a dense mode basis.

Parameters
copyboolean

Whether to force a copy or not. A copy is always made if the current ModeBasis is not dense.

Returns
ModeBasis

The densified ModeBasis.

to_sparse(self, copy=False)

Convert the mode basis to a sparse mode basis.

Parameters
copyboolean

Whether to force a copy or not. A copy is always made if the current ModeBasis is not sparse.

Returns
ModeBasis

The sparsified ModeBasis.

Raises
TypeError

If this ModeBasis cannot be sparsified.