How magesh-ram/afr-framework works
Purpose and Topology
AFR is a domain-agnostic adaptive multi-horizon forecasting framework. It combines a pluggable scientific Python core with a FastAPI REST backend and React/Vite dashboard. Its decision output is a calibrated forecast interval plus reliable horizon H*: the longest forecast prefix meeting a configured risk budget.
Primary runtime entry points are app/main.py (uvicorn app.main:app) and frontend/src/main.jsx. Offline preparation and study execution enter through scripts/preprocess.py, scripts/run_calibration_study.py, and scripts/run_deep_validation.py.
Scientific Pipeline and Contracts
The core orchestration and replaceable-role contracts are in parc/core/pipeline.py, parc/core/interfaces.py, and parc/core/types.py. A registry/capability layer in parc/core/registry.py selects and validates compatible forecast, uncertainty, calibration, and reliability implementations before a run; incompatible pairings are rejected rather than silently substituted.
The pipeline is intentionally data-domain independent. Dataset-specific NYC Taxi handling is outside the core contract.
Data Ingestion, Features, and Splits
Input CSVs or bundled taxi data enter through parc/data/ingest.py and app/services/datasets.py. The data layer validates time-series inputs, derives modeling features, preprocesses observations, and creates train/calibration/test temporal partitions via parc/data/features.py, parc/data/preprocessing.py, and parc/data/splits.py.
Processed NYC panels and metadata are materialized under data/processed/; bundled demo/source datasets reside in app/demo_data/ and sample_data/. scripts/preprocess.py is the raw-TLC-to-processed-data boundary.
Forecast and Uncertainty Providers
Forecast providers generate point paths using baseline, linear, GBM, or neural implementations: parc/forecast/baselines.py, parc/forecast/gbm.py, and parc/forecast/deep.py. Neural execution is runtime-controlled by backend settings, so deployment can retain LightGBM functionality while refusing neural requests.
Uncertainty providers attach predictive spread to a forecast through residual, intrinsic-model, or MC-dropout approaches in parc/uncertainty/residual.py, parc/uncertainty/model_intrinsic.py, and parc/uncertainty/mc_dropout.py. This boundary lets models with native quantiles differ from models requiring post-hoc residual uncertainty.
Calibration, Reliability, and Evaluation
Calibration transforms raw uncertainty into published intervals using identity and conformal methods in parc/calibration/identity.py and parc/calibration/conformal.py; diagnostics are in parc/calibration/diagnostics.py.
The reliability controller consumes published intervals and the risk budget to compute per-horizon risk and H*, without realized future outcomes in the certificate signature. Adaptive/static control and monitoring live in parc/reliability/controller.py and parc/reliability/monitors.py. Aggregate quality metrics are produced by parc/evaluation/metrics.py; research outputs are persisted in reports/.
Backend API and Experiment Lifecycle
FastAPI application setup, CORS, health probing, and configuration limits are in app/main.py and app/config.py. REST routing is centralized in app/api/routes.py; request/response contracts are in app/schemas/experiment.py.
Service modules form the API-to-core boundary: experiment execution/caching in app/services/experiments.py, dataset handling in app/services/datasets.py, catalog/configuration exposure in app/services/catalog.py, and downloadable result generation in app/services/exports.py. Upload size, row count, horizon, training epoch, and MC-pass caps protect the service runtime.
Frontend and Deployment Boundaries
The SPA uses frontend/src/api/client.js to call the /api backend configured at build time. frontend/src/App.jsx and page modules such as frontend/src/pages/NewExperiment.jsx, frontend/src/pages/Results.jsx, and frontend/src/pages/Dashboard.jsx drive configuration, run state, and result visualization.
The backend is deployable on Render via render.yaml; the frontend targets Vercel through frontend/vercel.json. Material runtimes include Python/FastAPI, LightGBM, PyTorch for neural models, and Node-based React/Vite. No external database or secret-backed service is indicated; experiments and demo results are application-managed/cached.
Main entry points: pipeline.py Forecast pipeline · routes.py REST API · ingest.py Data preparation · experiments.py Experiment service
Components 20
Offline workflows
- Preprocess script · Converts raw TLC data into processed panels.
scripts/preprocess.py - Study runners · Calibration and deep-validation research runs.
scripts/run_calibration_study.py - Processed panels · NYC panels and metadata materialized for runs.
- Research reports
Scientific core
- Data preparation · Validates series, derives features, preprocesses, and splits time windows.
parc/data/ingest.py - Pipeline contracts · Pluggable forecast, uncertainty, calibration, and reliability roles.
parc/core/interfaces.py - Capability registry · Selects valid provider combinations and rejects incompatible ones.
parc/core/registry.py - Forecast pipeline · Runs the domain-agnostic forecasting workflow.
parc/core/pipeline.py - Forecast providers · Baseline, linear, GBM, and neural point forecasts.
parc/forecast/gbm.py - Uncertainty providers · Residual, intrinsic-model, or MC-dropout predictive spread.
parc/uncertainty/residual.py - Interval calibration · Identity or conformal conversion of raw uncertainty to intervals.
parc/calibration/conformal.py - Reliability controller · Computes per-horizon risk and longest reliable prefix H*.
parc/reliability/controller.py - Evaluation metrics · Aggregates forecast and interval quality metrics.
parc/evaluation/metrics.py
FastAPI service
- FastAPI app · Application setup, CORS, health checks, and runtime limits.
app/main.py - REST API · Centralized /api routing and experiment contracts.
app/api/routes.py - Experiment service · Executes and caches core pipeline runs.
app/services/experiments.py - Dataset service · Handles uploads, bundled data, and dataset preparation.
app/services/datasets.py - Catalog and exports · Exposes configuration catalog and downloadable results.
app/services/catalog.py
Dashboard
- React dashboard · Configuration, run state, and result visualization.
frontend/src/App.jsx - API client · Build-time configured client for the /api backend.
frontend/src/api/client.js
Connections 21
- Preprocess script → Data preparation: prepares
- Data preparation → Processed panels: materializes
- Study runners → Forecast pipeline: runs
- Forecast pipeline → Capability registry: validates selection
- Capability registry → Pipeline contracts: checks roles
- Forecast pipeline → Data preparation: uses prepared splits
- Forecast pipeline → Forecast providers: generates paths
- Forecast providers → Uncertainty providers: point forecasts
- Uncertainty providers → Interval calibration: raw spread
- Interval calibration → Reliability controller: published intervals
- Reliability controller → Evaluation metrics: risk certificate and H*
- Evaluation metrics → Research reports: persists study outputs
- FastAPI app → REST API: mounts
- REST API → Experiment service: run requests
- REST API → Dataset service: dataset requests
- REST API → Catalog and exports: catalog and downloads
- Dataset service → Data preparation: validates and prepares
- Experiment service → Forecast pipeline: executes
- Experiment service → Processed panels: reads cached panels
- API client → REST API: /api
- React dashboard → API client: uses