state_space

class nfoursid.state_space.StateSpace(a: numpy.ndarray, b: numpy.ndarray, c: numpy.ndarray, d: numpy.ndarray, k: Optional[numpy.ndarray] = None, x_init: Optional[numpy.ndarray] = None, y_column_names: Optional[List[str]] = None, u_column_names: Optional[List[str]] = None)

Bases: object

A state-space model defined by the following equations:

\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}

The shapes of the matrices are checked for consistency and will raise if inconsistent. If a matrix does not exist in the model representation, the corresponding np.ndarray should have dimension zero along that axis. See the example below.

An autonomous state-space model has no matrices B and D. An autonomous model with a one-dimensional internal state and output, can be represented as follows:

>>> model = StateSpace(
>>>     np.ones((1, 1)),
>>>     np.ones((1, 0)),
>>>     np.ones((1, 1)),
>>>     np.ones((1, 0))
>>> )
Parameters
  • a – matrix A

  • b – matrix B

  • c – matrix C

  • d – matrix D

  • k – matrix K, optional

  • x_init – initial state x_0 of the model, optional

  • y_column_names – list of output column names, optional

  • u_column_names – list of input column names, optional

output(x: numpy.ndarray, u: Optional[numpy.ndarray] = None, e: Optional[numpy.ndarray] = None)

Calculate the output of the state-space model. This function calculates the updated y_k of the state-space model in the class description. The current state x is required. Providing an input u is optional. Providing a noise term e to be added is optional as well.

plot_input_output(fig: matplotlib.figure.Figure)

Given a matplotlib figure fig, plot the inputs and outputs of the state-space model.

step(u: Optional[numpy.ndarray] = None, e: Optional[numpy.ndarray] = None) numpy.ndarray

Calculates the output of the state-space model and returns it. Updates the internal state of the model as well. The input u is optional, as is the noise e.

to_dataframe() pandas.core.frame.DataFrame

Return the inputs and outputs of the state-space model as a dataframe, where the columns are the input- and output-columns.