lmlib.statespace.cost.CostSegment#
- class lmlib.statespace.cost.CostSegment(alssm, segment, **kwargs)#
Bases:
lmlib.statespace.cost.CostBase
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 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 borders a and b in N, a < b
A cost segment is the quadratic cost function
\[J_a^b(k,x,\theta) = \sum_{i=k+a}^{k+b} \alpha_{k+\delta}(i)v_i(y_i - cA^{i-k}x)^2\]over a fixed interval \(\{a, \dots, b\}\) with \(a \in \mathbb{Z} \cup \{ - \infty \}\), \(b \in \mathbb{Z} \cup \{ + \infty\}\), and \(a \le b\), and with initial state vector \(x \in \mathbb{R}^{N \times 1}\). For more details, seen in Section 4.2.6 and Chapter 9 in [Wildhaber2019] .
- Parameters
Examples
Setup a cost segment with finite boundaries and a line ALSSM.
>>> alssm = lm.AlssmPoly(poly_degree=1, label="slope with offset") >>> segment = lm.Segment(a=-30, b=0, direction=lm.FORWARD, g=20, label="finite left") >>> cost = lm.CostSegment(alssm, segment, label="left line") >>> print(cost) CostSegment : label: left line └- Alssm : polynomial, A: (2, 2), C: (1, 2), label: slope with offset, └- Segment : a:-30, b:0, fw, g:20, delta:0, label: finite left
Methods
__init__
(alssm, segment, **kwargs)eval_alssm_output
(xs[, alssm_weight])Evaluation of the
CostSegment
's ALSSM output for multiple state vectorsint : Order of the (stacked) Alssm Model
get_steady_state_W
([method])Returns Steady State Matrix W
trajectories
(xs[, alssm_weight, thd])Returns the ALSSM's trajectory (=output sequence for fixed initial state) for multiple initial state vectors
windows
([thd])Per-sample evaluation of the
CostSegment
's window.Attributes
Mapping matrix \(F\), maps models to segments
Set of ALSSM
Label of the Cost Model
Set of Segment
- eval_alssm_output(xs, alssm_weight=1.0)#
Evaluation of the
CostSegment
’s ALSSM output for multiple state vectorsFor parameter details see:
lmlib.statespace.models.Alssm.eval()
- get_model_order()#
int : Order of the (stacked) Alssm Model
- get_state_var_indices(label)#
Returns the state indices for a specified label of the stacked internal ALSSM
- Parameters
label (str) – state label
- Returns
out – state indices of the label
- Return type
list of int
- get_steady_state_W(method='closed_form')#
Returns Steady State Matrix W
- Parameters
method (str, optional) – if ‘closed_form’ is used the steady state matrix will be calculated in a close form. This method can be critical, as it can produce badly conditioned matrices internally. if ‘limited_sum’ is used, the steady state matrix will be calculated brute force, with a stop condition on a minimum change.
- Returns
Wss = `class – Steady State Matrix W
- Return type
numpy.ndarray`
- trajectories(xs, alssm_weight=1.0, thd=1e-06)#
Returns the ALSSM’s trajectory (=output sequence for fixed initial state) for multiple initial state vectors
Evaluates the
CostSegment
’s ALSSM with the state vectors xs over the time indices defined byCostSegment.segment
. The segment’s interval boundaries limit the evaluation interval (samples outside this interval are set to 0). In particular for segments with infinite interval borders, the threshold optionthd
additionally limits the evaluation boundaries by defining a minimal window height of theCostSegment.segment
.- Parameters
xs (array_like of shape=(XS, N [,S]) of float) – List of length XS with initial state vectors \(x\)
thd (float or None, optional) – Threshold setting the evaluation boundaries by setting a minimum window height
- Returns
trajectories – Each element in trajectories is a tuple with
range
of length JR: relative index range of trajectory with respect to semgent’s boundaries.array
of shape=(JR, L, [S]): trajectory values over reported range.
Dimension S is only present in the output, if dimension S is present in xs (i.e., if multiple signal sets are used)
- Return type
list of shape=(XS) of tuples
(range, array)
JR : index range length
XS : number of state vectors in a list
N : ALSSM system order, corresponding to the number of state variables
S : number of signal sets
L : output order / number of signal channels
- windows(thd=1e-06, *args)#
Per-sample evaluation of the
CostSegment
’s window.Returns the index range and the per-index window weights defined by the CostSegment’s
Segment
.For parameter list see:
Segment.windows()