
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@neural-trader/example-energy-forecasting
Advanced tools
Self-learning energy forecasting with conformal prediction and swarm-based ensemble models
Self-learning energy forecasting with conformal prediction and swarm-based ensemble models.
npm install @neural-trader/example-energy-forecasting
import { EnergyForecaster, EnergyDomain, ModelType } from '@neural-trader/example-energy-forecasting';
// Create forecaster
const forecaster = new EnergyForecaster(EnergyDomain.SOLAR, {
alpha: 0.1, // 90% confidence intervals
horizon: 48, // 48-hour forecast
seasonalPeriod: 24, // Daily seasonality
enableAdaptive: true,
ensembleConfig: {
models: [ModelType.ARIMA, ModelType.LSTM, ModelType.PROPHET]
}
});
// Train with historical data
const historicalData = [
{ timestamp: Date.now(), value: 150 },
// ... more data points
];
await forecaster.train(historicalData);
// Generate forecast
const forecast = await forecaster.forecast(48);
// Access predictions with confidence intervals
forecast.forecasts.forEach(f => {
console.log(`Time: ${new Date(f.timestamp).toISOString()}`);
console.log(`Forecast: ${f.pointForecast}`);
console.log(`Interval: [${f.interval.lower}, ${f.interval.upper}]`);
console.log(`Confidence: ${f.confidence * 100}%`);
});
Main forecasting system that orchestrates ensemble models and conformal prediction.
const forecaster = new EnergyForecaster(EnergyDomain.SOLAR, config);
await forecaster.train(data);
const forecast = await forecaster.forecast(48);
Swarm-based hyperparameter optimization and adaptive model weighting.
const ensemble = new EnsembleSwarm({
models: [ModelType.ARIMA, ModelType.LSTM],
adaptiveLearningRate: 0.05,
retrainFrequency: 100
});
await ensemble.trainEnsemble(trainingData, validationData);
Wrapper around @neural-trader/predictor for uncertainty quantification.
const predictor = new EnergyConformalPredictor(ModelType.ARIMA, {
alpha: 0.1,
calibrationSize: 2000
}, true); // adaptive mode
await predictor.initialize();
await predictor.calibrate(historicalData, predictions);
All models implement the ForecastingModel interface:
Run the included examples:
# Solar generation forecasting
npm run example:solar
# Wind power forecasting
npm run example:wind
# Electricity demand forecasting
npm run example:demand
# Temperature prediction
npm run example:temperature
interface ForecasterConfig {
alpha?: number; // Conformal prediction miscoverage rate (default: 0.1)
calibrationSize?: number; // Max calibration samples (default: 2000)
horizon?: number; // Default forecast horizon (default: 24)
seasonalPeriod?: number; // Seasonal period in hours (default: 24)
enableAdaptive?: boolean; // Enable adaptive conformal prediction (default: true)
ensembleConfig?: EnsembleConfig; // Ensemble configuration
weatherIntegration?: WeatherConfig; // Weather API integration
}
interface EnsembleConfig {
models: ModelType[]; // Models to include in ensemble
horizonWeights?: Map<number, Map<ModelType, number>>; // Custom horizon weights
adaptiveLearningRate?: number; // Learning rate for weight updates (default: 0.05)
retrainFrequency?: number; // Retraining frequency (default: 100)
minCalibrationSamples?: number; // Min samples for calibration (default: 50)
}
This package uses @neural-trader/predictor for statistically rigorous uncertainty quantification:
With conformal prediction, the forecaster provides mathematically guaranteed coverage:
P(y_true ∈ [lower, upper]) ≥ 1 - α
For α = 0.1, at least 90% of true values will fall within the prediction intervals.
Recommended models for each domain based on empirical performance:
The swarm exploration runs hyperparameter search in parallel:
// All model types explored concurrently
const explorationPromises = models.map(modelType =>
ensemble.exploreHyperparameters(modelType, data, validation)
);
await Promise.all(explorationPromises);
Comprehensive test suite with >90% coverage:
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # Coverage report
const horizonWeights = new Map([
[1, new Map([[ModelType.LSTM, 0.6], [ModelType.ARIMA, 0.4]])],
[24, new Map([[ModelType.PROPHET, 0.5], [ModelType.LSTM, 0.5]])],
]);
const forecaster = new EnergyForecaster(domain, {
ensembleConfig: {
models: [ModelType.LSTM, ModelType.ARIMA, ModelType.PROPHET],
horizonWeights
}
});
// Initial training
await forecaster.train(historicalData);
// Generate forecast
const forecast = await forecaster.forecast(24);
// Update with new observations as they arrive
for (const observation of newData) {
await forecaster.update(observation);
}
const stats = forecaster.getStats();
console.log('Domain:', stats.domain);
console.log('Training points:', stats.trainingPoints);
console.log('Models:', stats.ensembleStats.modelCount);
console.log('Seasonal strength:', stats.seasonalPattern?.strength);
// Per-model performance
stats.ensembleStats.performances.forEach(({ model, performance }) => {
console.log(`${model}: MAPE=${performance.mape}%, RMSE=${performance.rmse}`);
});
This package integrates seamlessly with the Neural Trader ecosystem:
Contributions welcome! Please ensure:
npm testnpm run lintnpm run typechecknpm run test:coverageMIT
FAQs
Self-learning energy forecasting with conformal prediction and swarm-based ensemble models
We found that @neural-trader/example-energy-forecasting demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.