nfoursid module

class dynamapp.nfoursid.NFourSID(dataframe: pandas.DataFrame, output_columns: List[str], input_columns: List[str] = None, num_block_rows: int = 2)[source]

Bases: object

Perform subspace identification using N4SID [1]. The state-space model under consideration, is:

\[\begin{split}\begin{cases} x_{k+1} &= A x_k + B u_k + K e_k \\ y_k &= C x_k + D u_k + e_k \end{cases}\end{split}\]

Data is provided as a dataframe dataframe where every row is a measurement. The output columns are given by output_columns. The input columns are given by input_columns.

The number of block rows to use in the block Hankel matrices is given by num_block_rows. If num_block_rows is chosen to be too big, the computational complexity will increase. If num_block_rows is chosen to be too small, the order of the system might not be possible to determine in the eigenvalue diagram. Moreover, if num_block_rows is chosen to be too small, the assumptions of [2] might not hold.

[1] Van Overschee, Peter, and Bart De Moor. "N4SID: Subspace algorithms for the identification of combined deterministic-stochastic systems." Automatica 30.1 (1994): 75-93.

subspace_identification()[source]

Perform subspace identification based on the PO-MOESP method. The instrumental variable contains past outputs and past inputs. The implementation uses a QR-decomposition for numerical efficiency and is based on page 329 of [1].

A key result of this function is the eigenvalue decomposition of the \(R_{32}\) matrix self.R32_decomposition, based on which the order of the system should be determined.

[1] Verhaegen, Michel, and Vincent Verdult. Filtering and system identification: a least squares approach. Cambridge university press, 2007.

system_identification(rank: int = None) Tuple[StateSpace, jax.numpy.ndarray][source]

Identify the system matrices of the state-space model given in the description of NFourSID. Moreover, the covariance of the measurement-noise and process-noise will be estimated. The order of the returned state-space model has rank rank by reducing the eigenvalue decomposition. The implementation is based on page 333 of [1].

The return value consists of a tuple containing

  • The identified state-space model containing the estimated matrices \((A, B, C, D)\),

  • and an estimate of the covariance matrix of the measurement-noise \(w\) and process-noise \(v\). The structure of the covariance matrix corresponds to the parameter noise_covariance of subspace_identification.kalman.Kalman. See its documentation for more information.

self.system_identification needs the QR-decomposition result of subspace identification self.R32, and therefore can only be ran after self.subspace_identification.

[1] Verhaegen, Michel, and Vincent Verdult. Filtering and system identification: a least squares approach. Cambridge university press, 2007.