state_space_model¶
Classes
|
Class to compose several State Space Models. |
Class for Daily Seasonality State Space Model. |
|
|
Class for Level State Space Model. |
Class for Level-Trend State Space Model. |
|
|
Base class for State Space Model. |
|
Class for Seasonality State Space Model. |
Class for Weekly Seasonality State Space Model. |
|
Class for Yearly Seasonality State Space Model. |
- class CompositeSSM(seasonal_ssms: List[etna.models.nn.deepstate.state_space_model.SeasonalitySSM], nonseasonal_ssm: Optional[Union[etna.models.nn.deepstate.state_space_model.LevelSSM, etna.models.nn.deepstate.state_space_model.LevelTrendSSM]] = None)[source]¶
Class to compose several State Space Models.
Create instance of CompositeSSM.
- Parameters
seasonal_ssms (List[etna.models.nn.deepstate.state_space_model.SeasonalitySSM]) – List with the instances of Seasonality State Space Models.
nonseasonal_ssm (Optional[Union[etna.models.nn.deepstate.state_space_model.LevelSSM, etna.models.nn.deepstate.state_space_model.LevelTrendSSM]]) – Instance of Level or Level-Trend State Space Model.
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray [source]¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int [source]¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class DaylySeasonalitySSM[source]¶
Class for Daily Seasonality State Space Model.
Create instance of SeasonalitySSM.
- Parameters
num_seasons – Number of seasons in the considered seasonality period.
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray ¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- get_timestamp_transform(x: pandas._libs.tslibs.timestamps.Timestamp)[source]¶
Generate datetime index to use in the State Space Model.
- Parameters
x (pandas._libs.tslibs.timestamps.Timestamp) – timestamp
- Returns
Datetime index for State Space Model.
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int ¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class LevelSSM[source]¶
Class for Level State Space Model.
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray [source]¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int [source]¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class LevelTrendSSM[source]¶
Class for Level-Trend State Space Model.
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray ¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int [source]¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class SSM[source]¶
Base class for State Space Model.
The system dynamics is described with the following equations:
\[y_t = a^T_t l_{t-1} + b_t + \sigma_t\varepsilon_t\]\[l_t = F_t l_{t-1} + g_t\epsilon_t\]\[l_0 \sim N(\mu_0, diag(\sigma_0^2)), \varepsilon_t \sim N(0, 1), \epsilon_t \sim N(0, 1),\]where
\(y\) - state of the system
\(l\) - state of the system in the latent space
\(a\) - emission coefficient
\(F\) - transition coefficient
\(g\) - innovation coefficient
\(\sigma\) - noise standard deviation
\(\mu_0\) - prior mean
\(\sigma_0\) - prior standard deviation
- abstract emission_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- abstract generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray [source]¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- abstract innovation_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- abstract latent_dim() int [source]¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- abstract transition_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class SeasonalitySSM(num_seasons: int, timestamp_transform: Callable[[pandas._libs.tslibs.timestamps.Timestamp], int])[source]¶
Class for Seasonality State Space Model.
Create instance of SeasonalitySSM.
- Parameters
num_seasons (int) – Number of seasons in the considered seasonality period.
timestamp_transform (Callable[[pandas._libs.tslibs.timestamps.Timestamp], int]) –
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor [source]¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray [source]¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int [source]¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class WeeklySeasonalitySSM[source]¶
Class for Weekly Seasonality State Space Model.
Create instance of SeasonalitySSM.
- Parameters
num_seasons – Number of seasons in the considered seasonality period.
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray ¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- get_timestamp_transform(x: pandas._libs.tslibs.timestamps.Timestamp)[source]¶
Generate datetime index to use in the State Space Model.
- Parameters
x (pandas._libs.tslibs.timestamps.Timestamp) – timestamp
- Returns
Datetime index for State Space Model.
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int ¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type
- class YearlySeasonalitySSM[source]¶
Class for Yearly Seasonality State Space Model.
Create instance of SeasonalitySSM.
- Parameters
num_seasons – Number of seasons in the considered seasonality period.
- emission_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Emission coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Emission coefficient matrix.
- Return type
- generate_datetime_index(timestamps: numpy.ndarray) numpy.ndarray ¶
Generate datetime index to use in the State Space Model.
- Parameters
timestamps (numpy.ndarray) – Array with timestamps.
- Returns
Datetime index for State Space Model.
- Return type
numpy.ndarray
- get_timestamp_transform(x: pandas._libs.tslibs.timestamps.Timestamp)[source]¶
Generate datetime index to use in the State Space Model.
- Parameters
x (pandas._libs.tslibs.timestamps.Timestamp) – timestamp
- Returns
Datetime index for State Space Model.
- innovation_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Innovation coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Innovation coefficient matrix.
- Return type
- latent_dim() int ¶
Dimension of the latent space.
- Returns
Dimension of the latent space.
- Return type
int
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- transition_coeff(datetime_index: torch.Tensor) torch.Tensor ¶
Transition coefficient matrix.
- Parameters
datetime_index (torch.Tensor) – Tensor with the index values. Values should be from 0 to seasonal period.
- Returns
Transition coefficient matrix.
- Return type