GreenBox documentation
Everything about using GreenBox, from your first run to the method behind it.
What GreenBox does
GreenBox identifies polynomial models (NARMAX, NARX, ARX, ARMAX, FIR and truncated Volterra) from input/output data and selects them by a Green criterion that trades prediction error against arithmetic complexity, the cost of evaluating the model at every sample.
Besides the most accurate model, GreenBox gives a menu of Green models: one per decision method on the Pareto front of accuracy and complexity. A Green model often reaches almost the same accuracy with far fewer additions and multiplications, which saves computation, energy and CO₂e wherever the model runs.
Getting started
In the browser (recommended)
Open GreenBox in the browser. The interface runs entirely in the web browser with Python compiled to WebAssembly (Pyodide): there is nothing to install, and data files never leave the computer. It works on Windows, macOS and Linux in any recent browser. It needs an internet connection the first time to fetch Pyodide and Plotly from their CDNs.
The same app is a single file, dist/GreenBox.html: download it and open it by double-clicking. The file can be shared directly (e-mail, cloud drive).
Offline, with no internet at all
Run python tools/build_offline.py to create dist/GreenBox-offline/ and dist/GreenBox-offline.zip (~13 MB). Unzip, keep the lib folder next to GreenBox.html, and double-click it. Python, NumPy and Plotly are bundled; only .mat files need internet (SciPy is not bundled; use CSV instead). Tested offline in Edge (Chromium) and WebKit (Safari engine) on macOS. Phones are not supported for local files: mobile browsers do not run JavaScript from local HTML files reliably.
Desktop application (Windows)
Download GreenBox-Setup.exe (installer) or GreenBox-Windows.zip (portable) from the latest release. The desktop application runs the same interface with native Python and needs no internet. The installer is not signed, so on the first launch Windows SmartScreen may show Windows protected your PC: click More info, then Run anyway. To build it from source, see desktop/README.md.
Python package
The algorithms can be used from Python without the interface: see Python package.
The five steps
- Data: CSV/TXT/DAT or
.mat. Use one record split into estimation and validation, or a separate validation record. Optional cut, decimation and normalisation. Five examples are built in: DC motor, Silverbox, EMPS, three-story structure and Wiener–Hammerstein. - Model structure: family, nonlinearity degree, lags of y, u and e, u(k) feed-through, constant term.
- Complexity: how a multiplication is weighted against an addition (see Complexity), including calibration on your own computer.
- Identification: one Green model per decision method on the Pareto set (cheapest, ε-constraint, weighted sum, Euclidean, Tchebycheff, most accurate), and for the weighted methods one per accuracy weight wE in a chosen range. Noise models use extended least squares.
- Results: free-run validation, complexity vs. NRMSE with the Pareto front, every distinct Green model with the methods and weights that picked it (or the models of one method), the model equation, residual correlation tests, and CSV/JSON export.
Data file format
One signal per column, one sample per row, sampled at a constant rate. A file needs at least two columns: the input u(k) and the output y(k). Other columns (time, other sensors) may be present; you choose which column is the input and which is the output under Signals.
u,y
0.00,-0.013
1.00,-0.011
1.00, 0.042
…
- Header (recommended): a first line with the column names, e.g.
u,yorvoltage,speed. Without a header the columns are called col1, col2, … - Separator: comma, semicolon, tab or spaces. With a semicolon or tab the decimal mark can be a comma (
1,5;2,25, as saved by Excel in Portuguese or other European languages). - Files: .csv, .txt, .dat, .tsv (UTF-8, UTF-16 or Latin-1) or MATLAB .mat (each vector or matrix column becomes a signal). Excel files (.xlsx) are not read: use File → Save as → CSV.
- Ignored lines: lines starting with # or %, and text lines such as a units line under the header. Empty cells and NaN are treated as missing; samples where u or y is missing are dropped.
- Validation: either one record that GreenBox splits in two (One record, split in two), or separate estimation and validation records, in the same file (e.g. columns
uEst,yEst,uVal,yVal, which may have different lengths) or in two files. - Only single-input, single-output (SISO) models are identified. If the signals are stored in rows instead of columns, GreenBox transposes them.
Reading the results
The results report the change in complexity and in validation NRMSE of every Green model relative to the most accurate Green model of the run. Click a row of the summary table to inspect that model: its free-run simulation on the validation data, its place on the complexity–error plane and the Pareto front, its equation (process and, for NARMAX/ARMAX, noise) and the residual correlation tests.
Every figure, table and equation can be exported (CSV, PDF, SVG, PNG), and Save results… writes the whole run as CSV/JSON.
Green models
Terms are ranked with forward orthogonal least squares, a Householder QR with column pivoting on the Error Reduction Ratio (ERR).
Hold-out simulation (default). For every structure the Green structure search visits, candidate models come from several term orders ranked on the first part of the estimation data: ERR, ERR per unit of cost, the classical Green order, and the most accurate of these with terms removed one by one (backward elimination, by error and by error per unit of cost saved). Each candidate is simulated in free run on the held-out part. It is admissible when it does not diverge and reaches the minimum hold-out R² of Green models (default 0.75). The hold-out NRMSE E and the complexity C are scaled to 0–1 over the admissible candidates (Ê, Ĉ), and each selected decision method on the Pareto set (Chankong & Haimes, 1983) picks one Green model:
| Method | Chooses the admissible candidate that minimises |
|---|---|
| Cheapest | Ĉ |
| ε-constraint | Ĉ subject to Ê ≤ ε (default ε = 0.5) |
| Weighted sum (p = 1) | wEÊ + wCĈ |
| Euclidean (p = 2) | √((wEÊ)² + (wCĈ)²) |
| Tchebycheff (p = ∞) | max(wEÊ, wCĈ) |
| Most accurate | Ê |
with wC = 1 − wE and equal weights by default (wE = 0.5). A range of weights (from, to, step; green_weights in scripts) gives one model per weight for the p = 1, 2, ∞ methods. A candidate picked by several methods or weights is one model (same model_key). Every method returns a Pareto-optimal candidate; the cheapest and the most accurate bound the others. The chosen model is re-estimated on all estimation data and must stay bounded in free run over it. Validation data are never used for any choice.
Model size
Candidate terms are ranked by ERR. The number of terms is chosen by free-run simulation on a hold-out part of the estimation data: the last 30 % is held out, terms are ranked on the rest, and each candidate is scored by the worse of two free-run R² values, on the hold-out and on a window spanning the end of the fitted part and the hold-out. The validation data are never used for any choice. Candidate terms that are linear combinations of the terms already selected (e.g. u² = u for a 0/1 input) are skipped unless "Keep linearly dependent candidate terms" is ticked (classical procedure).
Structure search
The automatic search uses the estimation data only: a scan of linear models with 1 to 100 lags locates the memory of the system, then a hill climb on a lag ladder (1–6, 8, 10, 12, 15, 20, 25, 30, 40, …) for every degree keeps the structure that simulates the hold-out part of the estimation data best (the simplest one within 5 %). Hold-out = the last 30 % of the estimation data by default; the validation data are never used for any choice.
Linearity check
Before choosing a model family it helps to know whether the system is linear. GreenBox compares the best linear model with the best nonlinear polynomial model (free-run R² on the hold-out estimation data) and runs the Billings–Voon correlation test ry′y′², with Bartlett's variance for the confidence band. The verdict is linear, weakly nonlinear or nonlinear, and a warning appears when a linear family (ARX, ARMAX, FIR) is used on a nonlinear system. On the examples: DC motor, nonlinear (the nonlinear model removes 91 % of the linear model's error); Silverbox, nonlinear.
NARMAX and ARMAX
The e(k) terms form the noise model. They are estimated by extended least squares to remove bias from the process parameters, set to zero in free-run simulation, and therefore not counted in the complexity. The interface shows the process and noise equations separately.
Classical procedure
With green_selection = "classical":
- term order: J = wE(1 − ERRnorm) + wC·Cnorm, at each step
- model size: J = wE·ERRlossnorm + wC·Cnorm, over k terms
The one-step ERR can look almost perfect for models that drift or diverge in simulation, which is why the hold-out choice is the default. For scripts, run(..., {"run_standard": True}) still adds the classical reference model of the original Green-Box (ERR ranking, size by simulation or by AIC/BIC/FPE), which then becomes the reference; the interface does not use it.
Complexity
A model with a additions and b multiplications per sample costs C = a·c+ + b·c×. Because C is min-max normalised, only ρ = c×/c+ affects which model is selected. Available cost models for B-bit operands (an addition costs B bit operations):
| Cost model | Multiplication M(B) | ρ at B = 64 |
|---|---|---|
| Karatsuba (original Green-Box) | B1.585 | 11.4 |
| Schoolbook | B² | 64 |
| Toom-Cook 3-way | Blog 5 / log 3 | 6.9 |
| Schönhage–Strassen | B·log₂B·log₂log₂B | 15.5 |
| Uniform operation count (default) | – | 1 |
| Calibrated on this computer | measured t× | measured |
Calibration
The default, processor arithmetic, measures the cost of one 64-bit floating-point addition and one multiplication on the processor of the computer running GreenBox: a chain of dependent operations gives the latency t+ and t× (on an Apple M2: 0.86 and 1.15 ns, ρ ≈ 1.33). In the browser the chain is WebAssembly, translated by the browser into native instructions (same values in any browser); the desktop application runs it as native machine code compiled in C when the application is built, so it works offline and needs no compiler on the user's computer. The optional model evaluation engines time whole polynomials in Python or JavaScript and fit t = t0 + t+a + t×b, so their costs also include the interpreter's work. From a terminal, python -m greenbox.calibration --pure gives the pure cost natively (needs a C compiler).
Carbon
Carbon per sample is the estimated execution time multiplied by an emission rate (default 121.81 mgCO₂e/min, from the Green Algorithms calculator). Calibrated costs are already times. Theoretical costs are anchored to a reference multiplication time. Both are estimates, not measured energy.
Python package
The algorithms live in greenbox/, which depends only on NumPy, and can be used without the interface. Install it from GitHub:
pip install git+https://github.com/thalitanazare/GreenBox
from greenbox import run
result = run({"family": "NARX", "degree": 2, "lag_y": 2, "lag_u": 2,
"green_methods": ["cheapest", "epsilon", "tchebycheff", "accurate"], "green_weights": [0.25, 0.5, 0.75],
"cost_model": "karatsuba"},
u_train, y_train, u_val, y_val, continuation=True)
For .mat files install the optional SciPy dependency: pip install "greenbox[mat] @ git+https://github.com/thalitanazare/GreenBox".
Tests
tests/ contains unit tests, regression tests that keep the classical procedure (ERR ranking, AIC size, classical Green choice) producing the same models on the bundled examples, and an identification battery.
The battery, tests/battery.py, holds the bundled examples and synthetic systems with known equations (linear and nonlinear, first and second order, low and high measurement noise, coloured noise, FIR and Volterra, step, white, binary and multisine inputs, few and many samples, a lightly damped system prone to divergence, a non-polynomial tank), all run with the interface's default settings. python tools/run_battery.py prints the results table; tests/test_battery.py checks that the most accurate Green model is accurate and finds the true terms, that no Green model diverges, costs more than it or falls below the minimum accuracy, and that every decision method picks a Pareto-optimal candidate.
Development
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest # unit, regression and battery tests (about 15 min)
python tools/build_web.py # rebuild dist/GreenBox.html after changing web/ or greenbox/
The single-file app is assembled from web/index.html, web/style.css, web/app.js, web/worker.js and the greenbox/ sources. Commit the rebuilt dist/GreenBox.html.
Paper results
The experiment scripts, archived results, tables and figures of the GreenBox paper are in paper/. See paper/reproduction.md for how to reanalyse the archived results or repeat the experiments.
Citation and references
Please cite the software as described in CITATION.cff (GitHub shows it under Cite this repository), giving the release you used.
T. Nazaré, K. Mahmoodi and E. Nepomuceno, "Green-Box System Identification and Carbon Footprint Analysis for Sustainable Computing", OCEANS 2023 – Limerick, IEEE, 2023.
Example data
- DC motor: the case study distributed with SysIdentPy (Lacerda et al., JOSS 2020).
- Silverbox (nonlinearbenchmark.org; Wigren & Schoukens, ECC 2013): estimation = first 10 000 samples of the filtered-Gaussian segment, validation = first 20 000 samples of the multisine part.
- EMPS robot-joint positioning system (nonlinearbenchmark.org; Janot, Gautier & Brunot, Nonlinear System Identification Benchmarks Workshop 2019): decimated from 1 kHz to 100 Hz.
- Wiener–Hammerstein (nonlinearbenchmark.org; Schoukens, Suykens & Ljung, SYSID 2009): estimation = first 10 000 samples of the estimation record, validation = first 20 000 samples of the test record.
- LANL three-story structure (Figueiredo et al., Los Alamos National Laboratory report LA-14393, 2009): undamaged-state tests 1 and 2.