ltv_disc_tune¶
MATLAB equivalent:
sidLTVdiscTune
ltv_disc_tune ¶
Lambda tuning for LTV state-space identification (validation or frequency-based).
ltv_disc_tune ¶
ltv_disc_tune(*args, method: str = 'validation', lambda_grid: ndarray | None = None, precondition: bool = False, algorithm: str = 'cosmic', segment_length: int | None = None, consistency_threshold: float = 0.9, coherence_threshold: float = 0.3) -> tuple
Tune the regularization parameter lambda for :func:sid.ltv_disc.
Two tuning strategies are available:
- Validation (default) -- grid search over lambda evaluated by trajectory prediction RMSE on held-out state data.
- Frequency -- compare the COSMIC frozen transfer function against
a non-parametric :func:
sid.freq_mapestimate using a Mahalanobis-like consistency score. Selects the largest lambda whose posterior bands are consistent with the non-parametric bands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Positional data arguments. Interpretation depends on method: Validation method (4 positional args):
Frequency method (2 positional args):
|
()
|
|
method
|
str
|
|
'validation'
|
lambda_grid
|
ndarray or None
|
Vector of candidate lambda values. Defaults:
|
None
|
precondition
|
bool
|
Passed through to :func: |
False
|
algorithm
|
str
|
Passed through to :func: |
'cosmic'
|
segment_length
|
int or None
|
(Frequency only) Outer segment length for :func: |
None
|
consistency_threshold
|
float
|
(Frequency only) Fraction of |
0.9
|
coherence_threshold
|
float
|
(Frequency only) Minimum coherence for a grid point to be
included in the consistency test. Default is |
0.3
|
Returns:
| Type | Description |
|---|---|
tuple
|
Return type depends on method: Validation method --
Frequency method --
|
Raises:
| Type | Description |
|---|---|
SidError
|
If method is not |
SidError
|
If the number of positional arguments is wrong for the chosen
method (code: |
Examples:
Validation-based tuning:
>>> import numpy as np
>>> import sid
>>> best, lam, losses = sid.ltv_disc_tune(
... X_train, U_train, X_val, U_val)
Frequency-based tuning (no validation data needed):
Custom lambda grid:
>>> grid = np.logspace(-1, 12, 30)
>>> best, lam, losses = sid.ltv_disc_tune(
... X_train, U_train, X_val, U_val, lambda_grid=grid)
Notes
Validation method algorithm:
- For each lambda in the grid, run :func:
sid.ltv_discon training data and compute the trajectory prediction RMSE on validation data. - Select the lambda with minimum RMSE.
- Re-run :func:
sid.ltv_discat the optimal lambda.
Frequency method algorithm (SPEC.md S8.11):
- Run :func:
sid.freq_mapper state component (SISO) to obtain non-parametric frequency response estimates with uncertainty. - For each lambda, run :func:
sid.ltv_discwith uncertainty and compute the frozen transfer function via :func:sid.ltv_disc_frozen. - Compute a Mahalanobis-like distance at each
(omega, t)grid point:d^2 = |G_frozen - G_data|^2 / (std_frozen^2 + std_data^2). - Count the fraction of grid points (above the coherence threshold)
where
d^2 < chi2_threshold(5.991 for 95% confidence, 2 DOF). - Select the largest lambda achieving >= consistency_threshold fraction. Falls back to the lambda with the best fraction if none meet the threshold.
Specification: SPEC.md S8.4, S8.11
References
.. [1] Carvalho, Soares, Lourenco, Ventura. "COSMIC: fast closed-form identification from large-scale data for LTV systems." arXiv:2112.04355, 2022. .. [2] Ljung, L. "System Identification", 2nd ed., Prentice Hall, 1999.
See Also
sid.ltv_disc : LTV state-space identification. sid.ltv_disc_frozen : Frozen transfer function from LTV model. sid.freq_map : Time-varying frequency response estimation.
Changelog
2026-04-08 : First version (Python port) by Pedro Lourenco.