projection_error()

projection_error()#

BasisMulti.projection_error(state, relative=True) float[source]#

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

This function computes \(\frac{\|\Q - \mathcal{P}(\Q)\|}{\|\Q\|}\), where \(\Q\) is the state and \(\mathcal{P}\) is the projection defined by project(). If state is one-dimensional then \(||\cdot||\) is the vector 2-norm. If state is two-dimensional then \(||\cdot||\) is the Frobenius norm.

Parameters:
state(n,) or (n, k) ndarray

Matrix of n-dimensional state vectors, or a single state vector. The first full_variable_sizes[0] entries correspond to the first state variable, the next full_variable_sizes[1] entries correspond to the second state variable, and so on.

relativebool

If True (default), return the relative projection error norm(state - project(state)) / norm(state). If False, return the absolute projection error norm(state - project(state)).

Returns:
float

Relative error of the projection (relative=True) or absolute error of the projection (relative=False).