tsfm provides an easy interface to use TimeSeries Foundational Models.
Project description
UML Diagram - TSFM Codebase
classDiagram
%% Exceptions
class TSFMError {
<<Exception>>
}
class InvalidInputError {
<<Exception>>
+__init__(message: str)
}
Exception <|-- TSFMError
TSFMError <|-- InvalidInputError
%% Output Classes
class ForecastOutput {
-df_preds: DataFrame
-meta: dict[str, Any]
+rmsfe: DataFrame
+mae: DataFrame
+me: DataFrame
+metric(name: Literal) DataFrame
+summary(digits: int) None
+plot_actual_vs_pred(horizon: int, ax: Axes, start: Timestamp, end: Timestamp, return_ax: bool) Axes
-_agg_mean(s: Series, name: str, post: Callable) DataFrame
-_summary(digits: int) str
}
%% Base Model (Abstract)
class Model {
<<Abstract>>
+registry: ClassVar[dict]
+name: property
+__init_subclass__(cls, name: str, **kwargs)
+build(name: str, **kwargs) Model
+_pred(df: DataFrame, y: str, X: list, ctx_len: int, horizon: int, oos_start: str)* DataFrame
+pred(df: DataFrame, y: str, X: list, ctx_len: int, horizon: int, oos_start: str) ForecastOutput
}
ABC <|-- Model
%% ARModel
class ARModel {
+_pred(df: DataFrame, y: str, X: list, ctx_len: int, horizon: int, oos_start: str) DataFrame
}
Model <|-- ARModel : name="armodel"
ARModel ..> InvalidInputError : raises
ARModel ..> ForecastOutput : creates
%% Moirai Model
class Moirai {
+get_model(ctx_len: int, horizon: int, n_covariates: int) MoiraiForecast
+_pred(df: DataFrame, y: str, X: list, ctx_len: int, horizon: int, oos_start: str) DataFrame
}
Model <|-- Moirai : name="moirai"
Moirai ..> ForecastOutput : creates
%% Moirai2 Model
class Moirai2 {
+get_model(ctx_len: int, horizon: int, n_covariates: int) Moirai2Forecast
+_pred(df: DataFrame, y: str, X: list, ctx_len: int, horizon: int, oos_start: str) DataFrame
}
Model <|-- Moirai2 : name="moirai2"
Moirai2 ..> ForecastOutput : creates
%% Data Module Functions
class DataModule {
<<module: data.py>>
+generator(n: int, phi: float, beta0: float, beta1: float, sigma: float, trend: float, season_period: int, season_ampl: float, seed: int) DataFrame
+split_is_oos(df: DataFrame, test_frac: float) tuple[DataFrame, DataFrame]
}
%% ARModel Helper Functions
class ARModelHelpers {
<<module: armodel.py>>
+create_lags(var: Series, lags: int) DataFrame
+get_design_matrix(ys: Series, y_lags: int, horizon: int) tuple[Series, DataFrame]
+fit(ys: Series, y_lags: int, horizon: int) RegressionResultsWrapper
+pred(ys: Series, y_lags: int, horizon: int, oos_start: str) Series
+build_oos_panel(ys: Series, y_lags: int, horizon: int, oos_start: str) DataFrame
-_to_month_end(idx: Index) DatetimeIndex
}
ARModel ..> ARModelHelpers : uses
%% Moirai Helper Functions
class MoiraiHelpers {
<<module: moirai.py>>
+make_fc_df(forecasts: list, y_true_series: Series) DataFrame
+prepare_data(df: DataFrame, y: str, X: list, horizon: int, oos_start: str) TestData
+MODEL_ID: str
}
Moirai ..> MoiraiHelpers : uses
%% Moirai2 Helper Functions
class Moirai2Helpers {
<<module: moirai2.py>>
+make_fc_df(forecasts: list, y_true_series: Series) DataFrame
+prepare_data(df: DataFrame, y: str, X: list, horizon: int, oos_start: str) TestData
+MODEL_ID: str
}
Moirai2 ..> Moirai2Helpers : uses
%% Output Helper Functions
class OutputHelpers {
<<module: outputs.py>>
+get_horizon_groupby(df: DataFrame) Index
}
ForecastOutput ..> OutputHelpers : uses
%% Relationships with external libraries
Model ..> ForecastOutput : returns
%% Package level
class TSFMPackage {
<<module: __init__.py>>
+ARModel
+Model
+Moirai
+Moirai2
+generator
}
TSFMPackage ..> ARModel : exports
TSFMPackage ..> Model : exports
TSFMPackage ..> Moirai : exports
TSFMPackage ..> Moirai2 : exports
TSFMPackage ..> DataModule : exports generator
%% Notes
note for Model "Registry pattern:\nSubclasses auto-register\nby name parameter"
note for ForecastOutput "Contains forecast results\nwith MultiIndex[cutoff, oos_date]\nand metrics calculation"
note for ARModel "Autoregressive model\nusing statsmodels OLS\nwith HAC standard errors"
note for Moirai "Pretrained foundation model\nfrom Salesforce\nmodel: moirai-1.1-R-small"
note for Moirai2 "Pretrained foundation model\nfrom Salesforce\nmodel: moirai-2.0-R-small\nuses uni2ts library"
Class Descriptions
Core Classes
-
Model (Abstract Base Class)
- Registry pattern for dynamic model creation
- All models inherit from this class
- Defines interface:
_pred()(abstract) andpred()(concrete) - Registry allows building models by name
-
ARModel
- Autoregressive time series model
- Uses statsmodels for OLS regression with HAC standard errors
- Does not support covariates (raises
InvalidInputError) - Implements expanding window forecasting
-
Moirai
- Wrapper for Salesforce's Moirai foundation model
- Supports covariates
- Uses GluonTS for data preparation
- Generates 100 samples for probabilistic forecasting
-
Moirai2
- Wrapper for Salesforce's Moirai 2.0 foundation model
- Supports covariates
- Uses uni2ts library for inference
- Uses quantile-based forecasting (median as point forecast)
Data Structures
- ForecastOutput
- Dataclass containing forecast results
- MultiIndex DataFrame: (cutoff, oos_date)
- Cached properties for metrics: RMSFE, MAE, ME
- Methods for summary statistics and plotting
Exceptions
-
TSFMError
- Base exception for the package
-
InvalidInputError
- Raised when input validation fails
Utility Modules
-
DataModule (data.py)
generator(): Simulates time series with AR, trend, seasonalitysplit_is_oos(): Splits data into train/test
-
Helper Functions
- ARModel helpers: lag creation, design matrix, OLS fitting
- Moirai helpers: forecast formatting, data preparation
- Moirai2 helpers: forecast formatting, data preparation (uni2ts-based)
- Output helpers: horizon grouping utilities
Architecture Patterns
- Registry Pattern: Models self-register via
__init_subclass__ - Template Method: Base
Model.pred()calls abstract_pred() - Dataclass:
ForecastOutputwith cached properties - Facade: Simple interface (
pred()) over complex forecasting logic
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tsfmecb-0.1.0.tar.gz
(9.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
tsfmecb-0.1.0-py3-none-any.whl
(13.2 kB
view details)
File details
Details for the file tsfmecb-0.1.0.tar.gz.
File metadata
- Download URL: tsfmecb-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef7cb699ffab513d69437a58c209ca63118cec8f4a4a62c2ea2e80cf1296e47
|
|
| MD5 |
32b341e12677e4a31e974070e8ff0145
|
|
| BLAKE2b-256 |
5797377de3777105f4c5dc2071b77d1a3bfbd52f663cfedc33bfe79f16da05bd
|
File details
Details for the file tsfmecb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tsfmecb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c701ac844a1e3d255a2824aa71a13537be479d2e18e4f89c3a10803ed29753f
|
|
| MD5 |
51d180bca11d6ae78baa12629662317b
|
|
| BLAKE2b-256 |
2ad732c26235c791cd57f0cba2b4d3b937eff3c3d656cc5142b645633bdc8dbe
|