lmlib.statespace.model.AlssmStacked#
- class lmlib.statespace.model.AlssmStacked(alssms, deltas=None, **kwargs)#
Bases:
lmlib.statespace.model.ModelBase
Creates a joined ALSSM generating a stacked output signal of multiple ALSSMs.
For \(M\) ALSSMs as in
Alssm
, we get the stacked model’s output \(\tilde{s}_k(\tilde{x}) = \tilde{y}_k\)\[\begin{split}\tilde{s}_k(\tilde{x}) = \begin{bmatrix} s_k^{(1)}(x_1) \\ \vdots \\ s_k^{(M)}(x_M) \\ \end{bmatrix} = \begin{bmatrix} y_1[k] \\ \vdots \\ y_M[k] \\ \end{bmatrix} = \tilde{y}[k] = \tilde{c} \tilde{A}^k \tilde{x} \ \ ,\end{split}\]where \(y_m[k]\) denotes the output of the m-th joined ALSSM. \(y_m[k]\) is either a scalar (for signle-channel ALSSMs) or a column vector (for multi-channel ALSSMs). Accordingly, the initial state vector is
\[\begin{split}\tilde{x} = \begin{bmatrix} x_1 \\ \vdots \\ x_M \\ \end{bmatrix}\end{split}\]where \(x_m[k]\) is the state vector of the m-th joined ALSSM.
Therefore, the internal model matrices of the joined model are set to the block diagonals
\[ \begin{align}\begin{aligned}\begin{split}\tilde{A} = \left[\begin{array}{c|c|c} A_1 & 0 & 0 \\ \hline 0 & \ddots & 0 \\ \hline 0 & 0 & A_{M} \end{array}\right]\end{split}\\\begin{split}\tilde{C} = \left[\begin{array}{c|c|c} \lambda_1 C_1 & 0 & 0 \\ \hline 0 & \ddots & 0 \\ \hline 0 & 0 & \lambda_M C_{M} \end{array}\right]\end{split}\end{aligned}\end{align} \]where \(A_m\) and \(C_m\) are the transition matrices and the output vectors of the joined models, respectively, and \(\lambda_1 ... \lambda_M \in \mathcal{R}\) are additional factors to weight each output individually.
For more details see [Wildhaber2019]
PDF Sec: Linear Combination of M Systems
- alssmstuple of shape(M) of ALSSMs
Set of M autonomous linear state space models
- deltas: list of shape=(M) of floats, optional
List of M scalar factors for each output matrix of the ALSSM in alssms. (default: deltas = None, i.e., all scalars are set to 1)
- **kwargs
Forwarded to
ModelBase
M : number of ALSSMs
>>> alssm_poly = lm.AlssmPoly(4, label="high order polynomial") >>> A = [[1, 1], [0, 1]] >>> C = [[1, 0]] >>> alssm_line = lm.Alssm(A, C, label="line") >>> stacked_alssm = lm.AlssmStacked((alssm_poly, alssm_line), label='stacked model') >>> print(stacked_alssm) A = [[1. 1. 1. 1. 1. 0. 0.] [0. 1. 2. 3. 4. 0. 0.] [0. 0. 1. 3. 6. 0. 0.] [0. 0. 0. 1. 4. 0. 0.] [0. 0. 0. 0. 1. 0. 0.] [0. 0. 0. 0. 0. 1. 1.] [0. 0. 0. 0. 0. 0. 1.]] C = [[1. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 1. 0.]]
Methods
__init__
(alssms[, deltas])Returns the internal structure of the ALSSM model as a string.
eval_state
(x)Evaluation of the ALSSM for a state vector x.
eval_states
(xs)Evaluation of the ALSSM for an array of state vectors xs.
get_state_var_indices
(label)Returns the state indices for a specified label
Retruns a list of state variable labels
set_state_var_label
(label, indices)Adds a label for one or multiple state variabels in the state vector.
trajectories
(xs, js)Evaluation of the ALSSM for an array state vectors xs at evaluation indeces js.
trajectory
(x, js)Evaluation of the ALSSM for a state vector x at evaluation indeces js.
update
()Model update
Attributes
State matrix \(A \in \mathbb{R}^{N \times N}\)
Output matrix \(C \in \mathbb{R}^{L \times N}\)
Initialized Output matrix \(C \in \mathbb{R}^{L \times N}\)
Model order \(N\)
Set of models
Output scaling factors for each ALSSM in alssms
Label of the model
Dictionary containing state variable labels and index
- property C_init#
Initialized Output matrix \(C \in \mathbb{R}^{L \times N}\)
- Type
ndarray
, shape=([L,] N)
- property deltas#
Output scaling factors for each ALSSM in alssms
- Type
np.ndarray
- dump_tree()#
Returns the internal structure of the ALSSM model as a string.
- Returns
out – String representing internal model structure.
- Return type
Examples
>>> alssm_poly = lm.AlssmPoly(4, label="high order polynomial.rst") >>> A = [[1, 1], [0, 1]] >>> C = [[1, 0]] >>> alssm_line = lm.Alssm(A, C, label="line") >>> stacked_alssm = lm.AlssmStacked((alssm_poly, alssm_line), label='stacked model') >>> print(stacked_alssm.dump_tree()) └-Alssm : stacked, A: (7, 7), C: (2, 7), label: stacked model └-Alssm : polynomial.rst, A: (5, 5), C: (1, 5), label: high order polynomial.rst └-Alssm : native, A: (2, 2), C: (1, 2), label: line
- eval_state(x)#
Evaluation of the ALSSM for a state vector x.
eval_state(…) returns the ALSSM output
\[s_0(x) = CA^0x = Cx\]for a state vector \(x\).
- Parameters
x (array_like of shape=(N[,S])) – State vector \(x\)
- Returns
s – ALSSM output
- Return type
ndarray
of shape=([L[,S]])
N : ALSSM system order, corresponding to the number of state variables
L : output order / number of signal channels
S : number of signal setsExamples
>>> A = [[1, 1], [0, 1]] >>> C = [1, 0] >>> alssm = lm.Alssm(A, C, label='line') >>> >>> x = [0.1, 3] >>> s = alssm.eval_state(x) >>> print(s) 0.1
- eval_states(xs)#
Evaluation of the ALSSM for an array of state vectors xs.
eval_states(…) returns the ALSSM output
\[s_0(x) = CA^0x = Cx\]for each state vector \(x\) from the array xs
- Parameters
xs (array_like of shape=(XS,N[,S])) – List of length XS with state vectors \(x\).
- Returns
s – ALSSM outputs
- Return type
ndarray
of shape=(XS,[L[,S]])
N : ALSSM system order, corresponding to the number of state variables
L : output order / number of signal channels
S : number of signal setsExamples
>>> A = [[1, 1], [0, 1]] >>> C = [1, 0] >>> alssm = lm.Alssm(A, C, label='line') >>> >>> xs = [[0.1, 3], [0, 1], [-0.8, 0.2], [1, -3]] >>> s = alssm.eval_states(xs) >>> print(s) [ 0.1 0. -0.8 1. ]
- get_state_var_indices(label)#
Returns the state indices for a specified label
- Parameters
label (str) – state label
- Returns
out – state indices of the label
- Return type
list of int
- get_state_var_labels()#
Retruns a list of state variable labels
- Returns
out – list of state variable labels
- Return type
- set_state_var_label(label, indices)#
Adds a label for one or multiple state variabels in the state vector. Such labels are used to quickly referece to single states in the state vector by its names.
Examples
>>> alssm = lm.AlssmPoly(poly_degree=1, label='slope_with_offset') >>> alssm.set_state_var_label('slope', (1,)) >>> alssm.state_var_labels {'x': range(0, 2), 'x0': (0,), 'x1': (1,), 'slope': (1,)} >>> alssm.state_var_labels['slope'] (1,)
- trajectories(xs, js)#
Evaluation of the ALSSM for an array state vectors xs at evaluation indeces js.
trajectories(…) returns the ALSSM output
\[s_j(x) = CA^jx = Cx\]for a state vector \(x\) and index \(j\) in the list js
- Parameters
xs (array_like of shape=(XS,N[,S])) – List of length XS with state vectors \(x\).
js (array_like of shape=(J,)) – ALSSM evaluation indices
- Returns
s – ALSSM outputs
- Return type
ndarray
of shape=(XS, J, [L[,S]])
N : ALSSM system order, corresponding to the number of state variables
L : output order / number of signal channels
S : number of signal sets
j : ALSSM evaluation index
J : number of ALSSM evaluation indices
XS : number of state vectors in a listExamples
>>> A = [[1, 1], [0, 1]] >>> C = [1, 0] >>> alssm = lm.Alssm(A, C, label='line') >>> >>> xs = [[0.1, 3], [0, 1], [-0.8, 0.2], [1, -3]] >>> s = alssm.trajectories(xs, js=[0, 1, 2, 3, 4, 5]) >>> print(s)
- trajectory(x, js)#
Evaluation of the ALSSM for a state vector x at evaluation indeces js.
trajectory(…) returns the ALSSM output
\[s_j(x) = CA^jx = Cx\]for a state vector \(x\) and index \(j\) in the list js
- Parameters
x (array_like of shape=(N[,S])) – State vector \(x\)
js (array_like of shape=(J,)) – ALSSM evaluation indices
- Returns
s – ALSSM outputs
- Return type
ndarray
of shape=(J, [L[,S]])
N : ALSSM system order, corresponding to the number of state variables
L : output order / number of signal channels
S : number of signal sets
j : ALSSM evaluation index
J : number of ALSSM evaluation indicesExamples
>>> A = [[1, 1], [0, 1]] >>> C = [1, 0] >>> alssm = lm.Alssm(A, C, label='line') >>> >>> x = [0.1, 3] >>> s = alssm.trajectory(x, js=[0, 1, 2, 3, 4, 5]) >>> print(s)
- update()#
Model update
Updates the internal model (A and C Matrix) based on the initialization parameters of a class.