Uncertainty Fan Chart
Percentile bands (P5-P95, P25-P75, median) over time, for each output
variable that a Sensitivity batch carries. The script reads the collated
Output.csv of the batch, with the sample column populated.
The app bundles this script as Uncertainty_Fan_Chart.R and Uncertainty_Fan_Chart.py. Type the bare file name as a Script’s File, or pick it with Bundled scripts… on a Script row. A copy beside the Experiment file runs in place of the bundled one. See Run your own R or Python. Back to the Scripts.
| File | Needs |
|---|---|
Uncertainty_Fan_Chart.R | Rscript and ggplot2. Install it with install.packages("ggplot2") |
Uncertainty_Fan_Chart.py | python3, pandas, numpy and matplotlib. Install them with pip install pandas numpy matplotlib |
The two agree to 1e-9 on Uncertainty_Fan_Chart.csv. The test suite checks
this on every fixture. The test suite does not compare the chart PNGs between
the two languages. Check a rendered image by eye, not by byte.
Requirements
| Language | Needs |
|---|---|
| Python | Python 3.11 or later, with pandas, numpy and matplotlib. Install them with pip install pandas numpy matplotlib. |
| R | R 4.3 or later, with ggplot2. Install it with install.packages("ggplot2"). |
The test suite runs on these versions in GitHub Actions. Older versions are not tested.
What It Computes
For each output variable, at each time Output.csv carries:
- It collects the value of every Sample at that variable and time. It
excludes a value that is not a finite number (blank, non-numeric,
NaNorInf) from the distribution. It does not count that value. - It reads five percentiles off the values: P5, P25, the median (P50), P75 and P951.
The result goes to Uncertainty_Fan_Chart.csv beside Output.csv. It has
one row per (Variable, time) pair, with the Sample count behind each row.
The percentile is the default quantile() type of R, type 7. It is linear
interpolation between the two nearest order statistics. Python calls
numpy.percentile. The default interpolation of that function implements
the identical formula, so the two languages never drift onto different
quantile conventions.
Each Sample is a job row, told apart by the source_kind column. The
script skips saved_run rows.
The Output.csv of a sweep can carry more than one dataset.
EXPERIMENTER_DATASET selects one. If the file holds more than one dataset
and you select none, the script stops. It does not pool their Samples into
one distribution.
What It Prints
One summary line. It holds the variable count and the time-step count.
Each of these cases stops the script with a message that names the problem:
- a missing output folder, or a folder that does not exist
- a missing
Output.csv - a file that lacks
source,source_kind,variableorvalue - no
samplecolumn - a non-integer sample value
- more than one dataset with none selected
- no Sensitivity Sample left to band
- an unknown column
Reading the Chart
Uncertainty_Fan_Chart_<Variable>.png is one chart per output variable. It
draws the P5-P95 band outermost, the P25-P75 band inside it, and the median
as a line. Time is on the horizontal axis. The chart has axis labels and a
title that names the variable.
Why No Engine Restriction
Sensitivity_Indices computes PRCC. A PRCC needs the drawn parameter values
behind every Sample, which it reads from sample.csv in the job folder. A
percentile band needs no drawn parameter value. It needs only the output
values that a Sensitivity batch already scored for each Sample. Every engine
writes a Sample number into the sample column of Output.csv. This script
therefore reads the Output.csv of a Sensitivity batch, whichever engine ran
it and whichever method drew the sample.
Where It Runs
With no argument, the output folder comes from EXPERIMENTER_OUTPUT_DIR
and the time column from EXPERIMENTER_TIME_COLUMN. This is the shape that
an Experimenter Script step runs in. You can also give the folder of a
finished batch by hand as the first command-line argument. Then the script
finds the time column by elimination against the column set that
Experimenter publishes. The argument wins when you give both.
Rscript Uncertainty_Fan_Chart.R /path/to/Outputs/MySensitivityIn a Chain
The script reads Output.csv and writes Uncertainty_Fan_Chart.csv and one
Uncertainty_Fan_Chart_<variable>.png per variable into the same folder. It
writes one file for the whole batch, so no dataset name is in the file name.
No other script reads these files. See the chaining
rules.
Version Policy
The library README sets the format policy. The header of this file names the Experimenter version that it targets. The script checks every column before it computes anything. An unknown column stops the script with a message that names it. A version difference prints one line and does not stop the run.
References
- Hyndman, R.J., Fan, Y. (1996). Sample quantiles in
statistical packages. The American Statistician, 50(4), 361-365.
doi:10.2307/2684934. Defines the nine
quantile types that
quantile()of R implements. This script hand-rolls type 7, the default of R.