@neural-trader/example-energy-forecasting
v1.0.1
Published
Hourly energy forecasting in TypeScript (solar, wind, demand, temperature): ARIMA/Prophet/LSTM/Transformer ensemble with conformal prediction intervals from @neural-trader/predictor.
Maintainers
Readme
@neural-trader/example-energy-forecasting
Short-horizon forecasts for hourly energy series (solar, wind, electricity
demand, temperature) with conformal prediction intervals. Pure TypeScript on
top of @neural-trader/predictor, Node.js 18+.
What it does
EnergyForecaster: trains an ensemble on{ timestamp, value }points and returns multi-step forecasts, each with a point value and an interval at1 - alphacoverage.- Models: compact TypeScript implementations of ARIMA, Prophet-style seasonal decomposition, LSTM and Transformer, for demonstration rather than production accuracy.
EnsembleSwarm: tries a few hyperparameter settings per model and weights models by validation error.EnergyConformalPredictor: wraps the split and adaptive conformal predictors from@neural-trader/predictor.
Quickstart
npm install @neural-trader/example-energy-forecastingSave as quickstart.js and run node quickstart.js:
const { EnergyForecaster, EnergyDomain, ModelType } = require('@neural-trader/example-energy-forecasting');
// Four weeks of hourly electricity demand (MW): a daily cycle around 1000 MW
const start = Date.UTC(2026, 5, 1);
const history = Array.from({ length: 24 * 28 }, (_, h) => ({
timestamp: start + h * 3600e3,
value: 1000 + 200 * Math.sin((2 * Math.PI * (h % 24)) / 24),
}));
(async () => {
const forecaster = new EnergyForecaster(EnergyDomain.DEMAND, {
alpha: 0.1, // 90% prediction intervals
horizon: 6,
seasonalPeriod: 24,
ensembleConfig: { models: [ModelType.ARIMA, ModelType.PROPHET] },
});
await forecaster.train(history);
const { forecasts } = await forecaster.forecast(6);
forecasts.forEach((f, i) =>
console.log(`t+${i + 1}h`, f.pointForecast.toFixed(0), `[${f.interval.lower.toFixed(0)}, ${f.interval.upper.toFixed(0)}]`));
})();Expected output (training progress, then the forecasts; the true values for these six hours are 1052, 1100, 1141, 1173, 1193, 1200):
Training ensemble with 537 samples...
Exploring arima hyperparameters...
Exploring prophet hyperparameters...
arima trained with MAPE: 34.32%
prophet trained with MAPE: 24.15%
Initializing conformal predictors...
arima conformal predictor calibrated
prophet conformal predictor calibrated
Training complete!
t+1h 1033 [585, 1481]
t+2h 1112 [664, 1560]
t+3h 1186 [738, 1635]
t+4h 1250 [802, 1698]
t+5h 1300 [851, 1748]
t+6h 1331 [883, 1780]stderr also shows one warning: the hyperparameter search skips a weekly seasonal period that needs more history than four weeks.
Changes in 1.0.1
1.0.0 could not be installed: it depended on workspace:*, on agentdb@^2
(no such release) and on openrouter@^1 (no such package). 1.0.1 depends
only on @neural-trader/[email protected], the one package it imports.
License
MIT OR Apache-2.0. More packages: ruv.io.
