Demo utilities¶
Used to build the runnable examples in the Quickstart and Covariates pages.
tirex2.demo.Demo
dataclass
¶
A synthetic forecasting scenario for showcasing TiRex-2, built by
:meth:create_nonstationary_demo or :meth:create_holidays_demo.
Bundles a target series (split into context and held-out future) with the
covariates that explain it, and converts to a :class:~tirex2.model.types.TimeseriesType
ready to pass to :meth:~tirex2.api_adapter.forecast.ForecastModel.forecast.
Examples:
>>> from tirex2 import load_model
>>> from tirex2.demo import Demo, plot_demo_forecast
>>> model = load_model("NX-AI/TiRex-2", device="cpu")
>>> demo = Demo.create_nonstationary_demo()
>>> ts_univariate = demo.to_timeseries_type(include_covariates=False)
>>> ts_multivariate = demo.to_timeseries_type(include_covariates=True)
>>> forecasts = model.forecast(
... timeseries=[ts_univariate, ts_multivariate],
... prediction_length=demo.horizon,
... output_type="numpy",
... )
>>> fig = plot_demo_forecast(demo, *forecasts, engine="matplotlib")
Source code in src/tirex2/demo.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
create_nonstationary_demo
classmethod
¶
create_nonstationary_demo(context_length: int = 540, horizon: int = 42, seed: int = 7) -> Demo
Non-stationary demand: a CONTINUOUS future-known driver sets the wandering baseline level, plus a BINARY promotion flag that adds spikes.
The baseline has no fixed mean (it follows a smoothed random walk + a slow swing that turns over inside the horizon), so the target's own history cannot say where the level is heading - only the continuous covariate can. The binary promotions add sharp spikes at irregular times. The model must use BOTH covariates: the continuous one to track the level, the flag for spikes.
Source code in src/tirex2/demo.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
create_holidays_demo
classmethod
¶
create_holidays_demo(context_length: int = 540, horizon: int = 42, seed: int = 20) -> Demo
ONE future-known holiday flag -> consistent multiplicative spike.
Source code in src/tirex2/demo.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
tirex2.demo.plot_demo_forecast ¶
plot_demo_forecast(demo: Demo, univariate_forecast: Tensor, multivariate_forecast: Tensor, max_context_to_show: int = 64, engine: str = 'plotly')
Source code in src/tirex2/demo.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |