LinearBasis#

class LinearBasis(entries, weights=None, check_orthogonality: bool = True, name: str = None)[source]#

Linear low-dimensional state approximation.

This class approximates high-dimensional states \(\q\in\RR^n\) as a linear combination of \(r\) basis vectors \(\v_1,\ldots,\v_r\in\RR^n\). The basis matrix \(\Vr = [~\v_1~~\cdots~~\v_r~]\in \RR^{n \times r}\) and an (optional) weighting matrix \(\W\in\RR^{n \times n}\) define the approximation.

The encoding from the high-dimensional space \(\RR^n\) to the low-dimensional space \(\RR^r\) is given by

\[\q \mapsto \qhat = \Vr\trp\W\q,\]

while the decoding from low-dimensional space \(\RR^r\) to the high-dimensional space \(\RR^n\) is defined as

\[\qhat \mapsto \breve{\q} = \Vr\qhat = \sum_{i=1}^r \hat{q}_i \v_i,\]

where \(\qhat = [\hat{q}_1,\ldots,\hat{q}_r]\trp\in\RR^r\).

Basis entries \(\Vr\) and the weights \(\W\) are specified explicitly in the constructor, not learned from state data.

Parameters:
entries(n, r) ndarray

Basis entries \(\Vr\in\RR^{n\times r}\).

weights(n, n) ndarray or (n,) ndarray None

Weight matrix \(\W\in\RR^n\) or its diagonal entries. If None (default), set \(\W\) to the identity.

check_orthogonalitybool

If True, raise a warning if the basis is not orthogonal, i.e., if \(\Vr\trp\W\Vr\) is not the identity.

namestr or None

Label for the state variable that this basis approximates.

Notes

Pair with a opinf.pre.ShiftScaleTransformer to do centered approximations of the form \(\q \approx\Vr\qhat + \bar{\q}\).

Properties:
entries#

Entries of the basis matrix \(\Vr\in\RR^{n \times r}\). Also accessible via indexing (basis[:]).

full_state_dimension#

Dimension \(n\) of the full state.

name#

Label for the state variable that this basis approximates.

reduced_state_dimension#

Dimension \(r\) of the reduced (compressed) state.

shape#

Dimensions \((n, r)\) of the basis.

weights#

Weight matrix \(\W \in \RR^{n \times n}\).

Methods:

compress

Map high-dimensional states to low-dimensional latent coordinates.

decompress

Map low-dimensional latent coordinates to high-dimensional states.

fit

Do nothing, the basis entries are set in the constructor.

load

Load a basis from an HDF5 file.

plot1D

Plot the basis vectors over a one-dimensional domain.

project

Project a high-dimensional state vector to the subset of the high-dimensional space that can be represented by the basis.

projection_error

Compute the error of the basis representation of a state or states.

save

Save the basis to an HDF5 file.

verify

Verify that compress() and decompress() are consistent in the sense that the range of decompress() is in the domain of compress() and that project() defines a projection operator, i.e., project(project(Q)) = project(Q).