AlssmStacked
¶
Bases: ModelBase
flowchart TD
lmlib.statespace.model.AlssmStacked[AlssmStacked]
lmlib.statespace.model.ModelBase[ModelBase]
lmlib.statespace.model.ModelBase --> lmlib.statespace.model.AlssmStacked
click lmlib.statespace.model.AlssmStacked href "" "lmlib.statespace.model.AlssmStacked"
click lmlib.statespace.model.ModelBase href "" "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\)
where \(y_m[k]\) denotes the output of the m-th joined ALSSM. \(y_m[k]\) is either a scalar (for single-channel ALSSMs) or a column vector (for multi-channel ALSSMs). Accordingly, the initial state vector is
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
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
Parameters:
-
alssms(iterable of ModelBase, length M) –Set of M autonomous linear state space models whose outputs are stacked.
-
lambdas(list of float or None, default:None) –List of M scalar factors \(\\lambda_m\) weighting each ALSSM's output matrix \(C_m\). Default: None (all factors set to 1).
-
**kwargs–Forwarded to
ModelBase.
Notes
M : number of ALSSMs
Example
>>> import lmlib as lm
>>>
>>> alssm_poly = lm.AlssmPoly(poly_degree=4, label="high order polynomial")
>>>
>>> A = np.array([[1, 1], [0, 1]])
>>> C = np.array([[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:
-
update–Recompute the block-diagonal A and C from the sub-ALSSMs and their lambda scaling factors.
-
eval_output–Evaluate the ALSSM output for one or more state vectors.
-
dump_tree–Return the internal ALSSM tree structure as a string.
-
set_state_var_label–Register a label for one or more state vector indices.
-
get_state_var_labels–Return all registered state-variable labels together with their index tuples.
-
get_state_var_indices–Return the state-vector indices for a state variable identified by its label.
-
get_alssm_output_dimension–Return the ALSSM output dimension \(Q\) (number of output channels).
Attributes:
-
alssms–list of ModelBase : The \(M\) sub-ALSSMs whose outputs are stacked.
-
lambdas–ndarray : Per-ALSSM output scaling factors \(\lambda_m\) (one per sub-ALSSM).
-
steady_state_basis– -
label–str : Label of the model
-
C_init–ndarray, shape=([Q,] N) : Initialized Output matrix \(C \in \mathbb{R}^{Q \times N}\) -
force_MC–bool : If True, a 1-D output vector
Cis broadcast to a 2-D array of shape(1, N)(multi-channel form). -
A–ndarray, shape=(N, N) : State matrix \(A \in \mathbb{R}^{N \times N}\) -
C–ndarray, shape=([Q,] N) : Output matrix \(C \in \mathbb{R}^{Q \times N}\) -
N–int : Model order \(N\)
-
Q–int : Number of output channels \(Q\).
-
is_MC–bool : True if the output matrix
Cis 2-D (multi-channel form), False if 1-D (scalar output).
Source code in lmlib/statespace/model.py
Methods¶
update
¶
Recompute the block-diagonal A and C from the sub-ALSSMs and their lambda scaling factors.
Source code in lmlib/statespace/model.py
eval_output
¶
Evaluate the ALSSM output for one or more state vectors.
Without evaluation index (js=None):
With evaluation indices (js provided):
Parameters:
-
xs(array_like of shape (..., N)) –State vector(s). The last dimension must equal the model order N.
-
js(array_like of shape (J,) or None, default:None) –Sequence of integer evaluation indices. If None, evaluates at \(j = 0\) only (i.e. returns \(Cx\)).
Returns:
-
s(ndarray) –If
jsis None: shape(..., [Q]). Ifjsis provided: shape(J, ..., [Q]). The[Q]dimension is present only whenis_MCis True.
Source code in lmlib/statespace/model.py
dump_tree
¶
dump_tree() -> str
Return the internal ALSSM tree structure as a string.
Returns:
-
out(str) –Multi-line string representing the nested ALSSM structure.
Example
>>> import lmlib as lm
>>> import numpy as np
>>> 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.dump_tree())
└-AlssmStacked, A: (7, 7), C: (2, 7), label: stacked model
└-AlssmPoly, A: (5, 5), C: (5,), label: high order polynomial
└-Alssm, A: (2, 2), C: (1, 2), label: line
Source code in lmlib/statespace/model.py
set_state_var_label
¶
Register a label for one or more state vector indices.
Labels allow state components to be referenced by name rather than by
numeric index; see get_state_var_indices.
Parameters:
-
label(str) –Label name to register.
-
indices(tuple of int) –State vector indices associated with this label.
Example
Source code in lmlib/statespace/model.py
get_state_var_labels
¶
Return all registered state-variable labels together with their index tuples.
Labels are accumulated recursively from all nested sub-ALSSMs, with
each label prefixed by the current model's label. The state
indices are adjusted to reflect the position within the combined
(block-diagonal) state vector.
Returns:
-
out(list of (str, tuple of int)) –List of
(label_string, indices)pairs.label_stringis a dot-separated path (e.g.'stacked.poly.x0') andindicesis the corresponding tuple of integer state-vector positions.
Source code in lmlib/statespace/model.py
get_state_var_indices
¶
Return the state-vector indices for a state variable identified by its label.
Parameters:
-
label(str) –Fully qualified state label (dot-separated path), as returned by
get_state_var_labels.
Returns:
-
out(tuple of int or list of int) –State-vector indices associated with
label. Returns an empty list iflabelis not found.