AlssmPolyMeixner
¶
AlssmPolyMeixner(poly_degree: int, segment, **kwargs)
Bases: ModelBase
flowchart TD
lmlib.statespace.model.AlssmPolyMeixner[AlssmPolyMeixner]
lmlib.statespace.model.ModelBase[ModelBase]
lmlib.statespace.model.ModelBase --> lmlib.statespace.model.AlssmPolyMeixner
click lmlib.statespace.model.AlssmPolyMeixner href "" "lmlib.statespace.model.AlssmPolyMeixner"
click lmlib.statespace.model.ModelBase href "" "lmlib.statespace.model.ModelBase"
ALSSM whose output basis is the Meixner polynomials, orthogonal under the geometric (exponential) weight \(\gamma^j\) on \(j = 0, 1, 2, \ldots\)
Unlike AlssmPoly (Pascal/monomial basis), which suffers from Gram
matrix condition numbers of \(\mathcal{O}(g^{2D})\), and
AlssmPolyLegendre, which requires a finite window specification,
AlssmPolyMeixner is designed for infinite or semi-infinite exponential
windows and keeps the composite Gram matrix near the theoretical minimum.
Mathematical background
The Meixner polynomials \(M_n(j;\,1,\gamma)\) satisfy
where \(\gamma = (g-1)/g < 1\) is the exponential decay of the backward segment and \(g > 1\) is its effective window length. The norms \(W_n\) are exact and closed-form, growing by the constant factor \(g/(g-1)\) per degree. \(\delta_{mn}\) is the kronecker delta.
Accepting a Segment
The recommended constructor is AlssmPolyMeixner(poly_degree, segment) which
infers all parameters from the Segment:
-
segment.direction→ selects \(A\): -
'bw'(backward): \(A = A_{\rm bw} = I - \tfrac{1}{g-1}\operatorname{triu}(\mathbf{1},1)\) — basis \(C A_{\rm bw}^j x = M_n(j;\gamma)\) at lag \(j \ge 0\). -
'fw'(forward): \(A = A_{\rm fw} = A_{\rm bw}^{-1}\) — the forward filter's internal \(A^{-1} = A_{\rm bw}\) step recovers the decaying Meixner basis at lags \(j \le 0\). -
segment.a(backward) orsegment.b(forward) → shifts \(C\) so that the Gram matrix remains \(W_{\rm ss}\) (diagonal) even when the segment does not start at \(j=0\): -
Backward \([a, \infty)\): \(C \leftarrow [1,\ldots,1]\,A_{\rm bw}^{-a}\) (makes \(C A^j x = M_n(j-a;\gamma)\) for \(j \ge a\)).
-
Forward \((-\infty, b]\): \(C \leftarrow [1,\ldots,1]\,A_{\rm bw}^{-b}\) (makes the relative basis start at the boundary \(j=b\)).
The g and direction attributes are always available.
Condition number
\(\kappa(W) = (g/(g-1))^D\), independent of the segment shift.
Notes
The Meixner polynomials used here are the standard (monic normalisation) \(M_n(x;\,1,\gamma) = {}_2F_1(-n,\,-x;\,1;\,1 - 1/\gamma)\).
Parameters:
-
poly_degree(int) –Polynomial degree \(D \geq 0\). The model order is \(N = D+1\).
-
segment(Segment) –Target segment. Encodes direction, \(g\), and boundary shift:
segment.g→ window size \(g\) (giving decay \(\gamma = (g-1)/g\)).segment.direction→'bw'selects \(A_{\rm bw}\);'fw'selects \(A_{\rm fw} = A_{\rm bw}^{-1}\).segment.a(BW, if finite) orsegment.b(FW, if finite) → shifts \(C\) to restore Gram matrix orthogonality when the segment does not start at the canonical origin.
Meixner orthogonality requires a semi-infinite support, so the segment must be backward with
b=+infor forward witha=-inf. -
**kwargs–Forwarded to
ModelBase(e.g.label).
Methods:
-
update–Recompute \(A\) and \(C\) from all stored parameters.
-
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:
-
steady_state_basis– -
poly_degree–int : Polynomial degree \(D\).
-
g–float : Effective window size \(g\) (read-only; from the segment).
-
direction–str : Segment direction
'bw'(backward) or'fw'(forward). -
shift–int : Boundary shift applied to \(C\); 0 for the canonical origin.
-
gamma–float : Exponential decay \(\gamma = (g-1)/g\).
-
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\).
-
alssms–list : Sub-ALSSMs that compose this model (empty for leaf nodes such as
Alssm). -
lambdas–ndarray: Per-ALSSM scalar output scaling factors \(\lambda_m\) applied to each sub-model's output matrix \(C_m\). -
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
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 | |
Methods¶
update
¶
Recompute \(A\) and \(C\) from all stored parameters.
Transition matrix \(A\):
- direction
'bw': \(A = A_{\rm bw} = I_N - \tfrac{1}{g-1}\,\operatorname{triu}(\mathbf{1}_N, 1)\) - direction
'fw': \(A = A_{\rm fw} = A_{\rm bw}^{-1}\)
Output vector \(C\) (before shift): \(C_{\rm base} = [1,\ldots,1]\).
Shift (when shift != 0):
\(C \leftarrow C_{\rm base}\,A_{\rm bw}^{-\text{shift}}\).
This ensures that for a backward segment \([a, \infty)\) with
shift = a, the output at absolute lag \(j\) is
\(M_n(j - a;\,\gamma)\) — orthogonal under the shifted window weight.
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.