CostSegment
¶
Bases: BaseCost, BaseCost1d
flowchart TD
lmlib.statespace.cost.CostSegment[CostSegment]
lmlib.statespace.cost.BaseCost[BaseCost]
lmlib.statespace.cost.BaseCost1d[BaseCost1d]
lmlib.statespace.cost.BaseCost --> lmlib.statespace.cost.CostSegment
lmlib.statespace.cost.BaseCost1d --> lmlib.statespace.cost.CostSegment
click lmlib.statespace.cost.CostSegment href "" "lmlib.statespace.cost.CostSegment"
click lmlib.statespace.cost.BaseCost href "" "lmlib.statespace.cost.BaseCost"
click lmlib.statespace.cost.BaseCost1d href "" "lmlib.statespace.cost.BaseCost1d"
Quadratic cost function defined by an ALSSM and a Segment.
A CostSegment is an implementation of [Wildhaber2019] PDF (Cost Segment)
==================
Class: CostSegment (= 1 ALSSM + 1 Segment)
==================
window weight
^
2_| ___ exponentially rising window of a segment
1_| ____/ <- normalized to 1 at index delta; to
0_| _________/ weight the cost function
segment
+----------------+
alssm | |
+----------------+
|--|-------|-----|----> k (time, relativ to the segment reference index 0)
a 0 delta b
a, b : segment interval boundaries (integers or ±∞), a < b
A cost segment is the quadratic cost function
over a fixed interval \(\{a, \dots, b\}\) with \(a \in \mathbb{Z} \cup \{ - \infty \}\), \(b \in \mathbb{Z} \cup \{ + \infty\}\), and \(a < b\), and with initial state vector \(x \in \mathbb{R}^{N \times 1}\). For more details, see Section 4.2.6 and Chapter 9 in [Wildhaber2019] .
Parameters:
-
alssm(ModelBase) –ALSSM defining the signal model.
-
segment(Segment) –Segment defining the window shape and recursion direction.
-
beta(float, default:1.0) –Non-negative scaling factor on this cost term. Default: 1.0.
-
label(str, default:'n/a') –Label of the CostSegment. Default:
'n/a'.
Examples:
Set up a cost segment with finite boundaries and a line ALSSM.
>>> import lmlib as lm
>>> alssm_line = lm.AlssmPoly(poly_degree=1, label="slope with offset")
>>> segment_left = lm.Segment(a=-30, b=0, direction=lm.FORWARD, g=20, label="finite left")
>>> cost = lm.CostSegment(alssm_line, segment_left, label="left line")
>>> print(cost)
CostSegment(label: left line)
└- AlssmPoly(A=[[1 1],[0 1]], C=[1 0], label=slope with offset),
└- Segment(a=-30, b=0, direction=fw, g=20, delta=0, label=finite left)
Methods:
-
get_alssm_order–Return the state-space order N of the attached ALSSM.
-
get_number_of_dimensions–Return 1 — a CostSegment always represents a single dimension.
-
get_alssm_output_dimension–Return the output dimension Q of the attached ALSSM.
-
get_steady_state_W–Compute the steady-state Gram matrix W for this cost segment.
-
get_state_var_indices–Return the state indices corresponding to a named state variable.
-
eval_alssm_output–Evaluate the ALSSM output for a set of state vectors.
-
get_alssms–Return a list containing the single ALSSM of this cost segment.
Attributes:
-
label–str : Label of the CostSegment.
-
alssm–ModelBase : The ALSSM signal model attached to this cost segment.
-
segment–Segment : The window/segment attached to this cost segment.
-
beta–float : Non-negative scaling factor \(\beta\) on this cost segment.
Source code in lmlib/statespace/cost.py
Methods¶
get_number_of_dimensions
¶
get_steady_state_W
¶
Compute the steady-state Gram matrix W for this cost segment.
Parameters:
-
dim_order(ignored, default:None) –Accepted for interface compatibility; unused for 1-D costs.
-
method(str, default:'schur') –Computation method:
'schur'(default),'closed_form', or'limited_sum'.
Returns:
-
W(ndarray of shape (N, N)) –Steady-state Gram matrix.
Source code in lmlib/statespace/cost.py
get_state_var_indices
¶
Return the state indices corresponding to a named state variable.
Parameters:
-
label(str) –State variable label as registered in the ALSSM.
Returns:
-
indices(list of int) –Indices into the state vector for the labelled variable.
Source code in lmlib/statespace/cost.py
eval_alssm_output
¶
Evaluate the ALSSM output for a set of state vectors.
Parameters:
-
xs(array_like of shape (..., N)) –State vectors; the last dimension must match the model order N.
-
alssm_weights(None, scalar, or array_like, default:None) –Output weights forwarded to
AlssmSum. Default: None.
Returns:
-
out(ndarray) –ALSSM output sequences for each state vector in
xs.