canari.component.baseline_component#
This module defines three components for modelling baselines including LocalLevel, LocalTrend, and LocalAcceleration.
- class canari.component.baseline_component.LocalAcceleration(std_error: float | None = 0.0, mu_states: list[float] | None = None, var_states: list[float] | None = None)[source]#
Bases:
BaseComponent
LocalAcceleration class, inheriting from Canari’s BaseComponent. It models baselines with a locally constant acceleration (linear speed and curvature level) over time. It has three hidden states level, trend, and acceleration.
- Parameters:
std_error (Optional[float]) – Standard deviation of the process noise. Defaults: initialized to 0.
mu_states (Optional[list[float]]) – Initial mean of the hidden state. Defaults: initialized to zeros.
var_states (Optional[list[float]]) – Initial variance of the hidden state. Defaults: initialized to zeros.
Examples
>>> from canari.component import LocalAcceleration >>> # With known mu_states and var_states >>> local_acc = LocalAcceleration(mu_states = [1, 2, 3], var_states = [1, 2, 3], std_error=0.3) >>> # With default mu_states and var_states >>> local_acc = LocalAcceleration(std_error=0.3) >>> local_acc.transition_matrix array([[1. , 1. , 0.5], [0. , 1. , 1. ], [0. , 0. , 1. ]]) >>> local_acc.observation_matrix array([[1, 0, 0]]) >>> local_acc.process_noise_matrix >>> local_acc.mu_states >>> local_acc.var_states
- class canari.component.baseline_component.LocalLevel(std_error: float | None = 0.0, mu_states: list[float] | None = None, var_states: list[float] | None = None)[source]#
Bases:
BaseComponent
LocalLevel class, inheriting from Canari’s BaseComponent. It models baselines with a locally constant level (zero speed) over time. It has one hidden state level.
- Parameters:
std_error (Optional[float]) – Standard deviation of the process noise. Defaults: initialized to zeros 0.
mu_states (Optional[list[float]]) – Initial mean of the hidden states. Defaults: initialized to zeros.
var_states (Optional[list[float]]) – Initial variance of the hidden states. Defaults: initialized to zeros.
Examples
>>> from canari.component import LocalLevel >>> # With known mu_states and var_states >>> level = LocalLevel(mu_states=[1], var_states=[1],std_error=0.5) >>> # With default mu_states and var_states >>> level = LocalLevel(std_error=0.5) >>> level.component_name 'local level' >>> level.states_name ['level'] >>> level.transition_matrix array([[1]]) >>> level.observation_matrix array([[1]]) >>> level.process_noise_matrix >>> level.mu_states >>> level.var_states
- class canari.component.baseline_component.LocalTrend(std_error: float | None = 0.0, mu_states: list[float] | None = None, var_states: list[float] | None = None)[source]#
Bases:
BaseComponent
LocalTrend class, inheriting from Canari’s BaseComponent. It models baselines with a locally constant speed over time (linear level). It has two hidden states level and trend.
- Parameters:
std_error (Optional[float]) – Standard deviation of the process noise. Defaults: initialized to 0.
mu_states (Optional[list[float]]) – Initial mean of the hidden state. Defaults: initialized to zeros.
var_states (Optional[list[float]]) – Initial variance of the hidden state. Defaults: initialized to zeros.
Examples
>>> from canari.component import LocalTrend >>> # With known mu_states and var_states >>> local_trend = LocalAcceleration(mu_states=[1, 2], var_states=[1, 2], std_error=0.3) >>> # With default mu_states and var_states >>> local_trend = LocalTrend(std_error=0.2) >>> level.component_name 'local trend' >>> local_trend.states_name ['level', 'trend'] >>> local_trend.transition_matrix array([[1, 1], [0, 1]]) >>> local_trend.observation_matrix array([[1, 0]]) >>> local_trend.process_noise_matrix >>> local_trend.mu_states >>> local_trend.var_states