@sipemu/anofox-forecast 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # @sipemu/anofox-forecast
2
+
3
+ WebAssembly bindings for [anofox-forecast](https://crates.io/crates/anofox-forecast), a comprehensive time series forecasting library.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @sipemu/anofox-forecast
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Example
14
+
15
+ ```javascript
16
+ import { TimeSeries, NaiveForecaster, ThetaForecaster } from '@sipemu/anofox-forecast';
17
+
18
+ // Create a time series from values
19
+ const data = [10, 12, 15, 14, 18, 20, 22, 25, 24, 28];
20
+ const ts = new TimeSeries(new Float64Array(data));
21
+
22
+ // Create and fit a forecaster
23
+ const model = new NaiveForecaster();
24
+ model.fit(ts);
25
+
26
+ // Generate predictions
27
+ const forecast = model.predict(5);
28
+ console.log('Predictions:', forecast.values);
29
+ ```
30
+
31
+ ### With Timestamps
32
+
33
+ ```javascript
34
+ import { TimeSeries } from '@sipemu/anofox-forecast';
35
+
36
+ const values = [10, 12, 15, 14, 18];
37
+ const timestamps = [
38
+ Date.parse('2024-01-01'),
39
+ Date.parse('2024-01-02'),
40
+ Date.parse('2024-01-03'),
41
+ Date.parse('2024-01-04'),
42
+ Date.parse('2024-01-05'),
43
+ ];
44
+
45
+ const ts = TimeSeries.withTimestamps(
46
+ new Float64Array(values),
47
+ new Float64Array(timestamps)
48
+ );
49
+ ```
50
+
51
+ ## Available Forecasters
52
+
53
+ ### Baseline Models
54
+
55
+ | Forecaster | Description | Parameters |
56
+ |------------|-------------|------------|
57
+ | `NaiveForecaster` | Last observation repeated | - |
58
+ | `MeanForecaster` | Historical mean | - |
59
+ | `SeasonalNaiveForecaster` | Same season from previous cycle | `period` |
60
+ | `RandomWalkDriftForecaster` | Random walk with trend | - |
61
+ | `SMAForecaster` | Simple Moving Average | `window` |
62
+ | `WindowAverageForecaster` | Rolling window average | `window_size` |
63
+ | `SeasonalWindowAverageForecaster` | Seasonal window average | `period`, `window` |
64
+
65
+ ### Exponential Smoothing Models
66
+
67
+ | Forecaster | Description | Parameters |
68
+ |------------|-------------|------------|
69
+ | `SESForecaster` | Simple Exponential Smoothing | `alpha` |
70
+ | `HoltForecaster` | Holt Linear Trend (Double ES) | `alpha`, `beta` |
71
+ | `HoltWintersForecaster` | Triple Exponential Smoothing | `alpha`, `beta`, `gamma`, `period` |
72
+ | `SeasonalESForecaster` | Seasonal Exponential Smoothing | `period` |
73
+ | `ETSForecaster` | ETS state-space model | `error`, `trend`, `seasonal`, `period` |
74
+ | `AutoETSForecaster` | Automatic ETS selection | - |
75
+
76
+ ### Theta Models
77
+
78
+ | Forecaster | Description | Parameters |
79
+ |------------|-------------|------------|
80
+ | `ThetaForecaster` | Standard Theta method | - |
81
+ | `OptimizedThetaForecaster` | Optimized Theta | - |
82
+ | `DynamicThetaForecaster` | Dynamic coefficient updates | `alpha` |
83
+ | `AutoThetaForecaster` | Automatic Theta selection | - |
84
+
85
+ ### ARIMA Models
86
+
87
+ | Forecaster | Description | Parameters |
88
+ |------------|-------------|------------|
89
+ | `ARIMAForecaster` | ARIMA | `p`, `d`, `q` |
90
+ | `SARIMAForecaster` | Seasonal ARIMA | `p`, `d`, `q`, `P`, `D`, `Q`, `period` |
91
+ | `AutoARIMAForecaster` | Automatic ARIMA selection | - |
92
+
93
+ ### Intermittent Demand Models
94
+
95
+ | Forecaster | Description | Parameters |
96
+ |------------|-------------|------------|
97
+ | `CrostonForecaster` | Croston's method | - |
98
+ | `TSBForecaster` | Teunter-Syntetos-Babai | - |
99
+ | `ADIDAForecaster` | Aggregate-Disaggregate approach | - |
100
+ | `IMAPAForecaster` | Multiple Aggregation Prediction | - |
101
+
102
+ ### Advanced Models
103
+
104
+ | Forecaster | Description | Parameters |
105
+ |------------|-------------|------------|
106
+ | `TBATSForecaster` | TBATS (complex seasonality) | `seasonal_periods[]` |
107
+ | `AutoTBATSForecaster` | Automatic TBATS | `seasonal_periods[]` |
108
+ | `MFLESForecaster` | Multiple Frequency LOESS | `seasonal_periods[]` |
109
+ | `MSTLForecasterWrapper` | MSTL decomposition | `seasonal_periods[]` |
110
+ | `GARCHForecaster` | GARCH volatility model | `p`, `q` |
111
+
112
+ ## Prediction Intervals
113
+
114
+ Some models support prediction intervals:
115
+
116
+ ```javascript
117
+ import { NaiveForecaster } from '@sipemu/anofox-forecast';
118
+
119
+ const model = new NaiveForecaster();
120
+ model.fit(ts);
121
+
122
+ // Get forecast with 95% prediction intervals
123
+ const forecast = model.predictWithIntervals(5, 0.95);
124
+
125
+ console.log('Point predictions:', forecast.values);
126
+ console.log('Lower bound:', forecast.lower);
127
+ console.log('Upper bound:', forecast.upper);
128
+ ```
129
+
130
+ ## API Reference
131
+
132
+ ### TimeSeries
133
+
134
+ - `new TimeSeries(values: Float64Array)` - Create from values
135
+ - `TimeSeries.withTimestamps(values, timestamps)` - Create with timestamps (ms since epoch)
136
+ - `ts.length` - Number of observations
137
+ - `ts.values` - Get values as array
138
+ - `ts.isEmpty()` - Check if empty
139
+ - `ts.hasMissingValues()` - Check for NaN values
140
+ - `ts.slice(start, end)` - Get a slice of the series
141
+
142
+ ### Forecast
143
+
144
+ - `forecast.horizon` - Number of predictions
145
+ - `forecast.values` - Point predictions
146
+ - `forecast.lower` - Lower prediction interval (if available)
147
+ - `forecast.upper` - Upper prediction interval (if available)
148
+ - `forecast.hasLower()` - Check if lower interval exists
149
+ - `forecast.hasUpper()` - Check if upper interval exists
150
+
151
+ ### ETS Model Specification
152
+
153
+ For `ETSForecaster`, use string codes:
154
+ - **Error**: `"A"` (additive) or `"M"` (multiplicative)
155
+ - **Trend**: `"N"` (none), `"A"` (additive), or `"Ad"` (additive damped)
156
+ - **Seasonal**: `"N"` (none), `"A"` (additive), or `"M"` (multiplicative)
157
+
158
+ ```javascript
159
+ // ETS(A,A,M) - Additive error, Additive trend, Multiplicative seasonal
160
+ const ets = new ETSForecaster("A", "A", "M", 12);
161
+ ```
162
+
163
+ ## Browser Usage
164
+
165
+ ```html
166
+ <script type="module">
167
+ import init, { TimeSeries, ThetaForecaster } from './anofox_forecast_js.js';
168
+
169
+ async function main() {
170
+ await init();
171
+
172
+ const data = new Float64Array([10, 12, 15, 14, 18, 20, 22, 25]);
173
+ const ts = new TimeSeries(data);
174
+
175
+ const model = new ThetaForecaster();
176
+ model.fit(ts);
177
+
178
+ const forecast = model.predict(5);
179
+ console.log('Forecast:', forecast.values);
180
+ }
181
+
182
+ main();
183
+ </script>
184
+ ```
185
+
186
+ ## Node.js Usage
187
+
188
+ ```javascript
189
+ import { TimeSeries, AutoARIMAForecaster } from '@sipemu/anofox-forecast';
190
+
191
+ // Load your data
192
+ const data = [/* your time series data */];
193
+ const ts = new TimeSeries(new Float64Array(data));
194
+
195
+ // Forecast with AutoARIMA
196
+ const model = new AutoARIMAForecaster();
197
+ model.fit(ts);
198
+ const forecast = model.predict(10);
199
+ ```
200
+
201
+ ## Limitations
202
+
203
+ - The `parallel` feature from the Rust crate is not available in WASM
204
+ - Postprocessing features (conformal prediction, IDR) are not yet exposed
205
+ - Cross-validation utilities are not yet exposed
206
+
207
+ ## License
208
+
209
+ MIT