On this page

Sensitivity and stochastic platforms

Manual contents | Tutorial | Model logic | Dashboard configuration | Where NuML runs

Alongside the ordinary Run platform, DynSS apps provide two analytical platforms that re-run the model many times: Sensitivity sweeps one parameter across a range and overlays the results; Stochastic repeats a random model and aggregates outcomes into histograms and statistics. Both are configured from NuML with #= statements — the part of the language the wiki reference does not document. Sources: directive.js, initSens.js, initStoc.js, numlTransformer.js.

Both platforms are optional: a program that omits SensPlatform / StocPlatform simply leaves those pages unconfigured.

1. What the platforms do

Platform Page Behavior
Run the app's main page one interactive simulation, as in the tutorial
Sensitivity the app's Sensitivity page runs the model once per value of a chosen parameter stepped across [lo, hi]; overlays the target's trajectories and graphs the mean ± standard deviation across runs
Stochastic the app's Stochastic page repeats the (random) model many times; records one value per run in a histogram and optionally tracks a series' mean ± standard deviation over time

The platforms replay the same NuML program; batch in the integration configuration is strongly recommended so each replicate runs at full speed.

2. Sensitivity analysis: SensPlatform

SensPlatform #= [
    title("Sensitivity to Harvest Rate"),
    sensTarget(N),                    // the quantity to observe
    sensParam("Harvest Rate (h)"),    // the slider to sweep, by legend
    sensRuns(11),                     // number of values to test
    sensLo(0.0),                      // low end of the sweep
    sensHi(0.3)                       // high end of the sweep
]
Directive Contract
title(text) heading for the sensitivity displays
sensTarget(arg) what to record. Unquoted (sensTarget(I)): a model variable or term — if it is not already routed by an update, the code normalizer wires it to a hidden TimeSeries automatically. Quoted (sensTarget("I")): must exactly match a legend string of one of the configured graphs. Never quitWhen or quitTime
sensParam("label") the swept parameter, named by the slider's legend string
sensRuns(n) how many evenly spaced parameter values to run
sensLo(x), sensHi(x) the sweep range (overriding the slider's own range for the study)

The platform's main graph overlays the target's trajectory for every swept value; its statistics graph plots the across-run mean and mean ± standard deviation at each time. Older presets spell the last three directives statRuns, statLo, statHi (and statParam/statDat for the parameter/target); the engine accepts both vocabularies — write the sens* forms in new code.

3. Repeated stochastic runs: StocPlatform

For models with randomness (binomial/poisson draws in next equations under Euler — see model logic):

StocPlatform #= [
    stocHist("TotNewInf"),                       // histogram datum
    binSize(10),
    stocHistTitle("Histogram of Total Infections"),
    stocRuns(500),                               // number of replicates
    stocStats(TimeGraph00, "Infected Untreated"), // optional statistics series
    stocStatsTitle("Infectious Count Statistics")
]
Directive Contract
stocRuns(n) number of replicate simulations
stocHist(arg) the one value recorded per run: a quoted legend or variable name records that series' final value; the special term quitTime records the time at which the run terminated (see section 5)
stocHistTitle(text) histogram title
stocHistLabel(text) histogram x-axis label
stocHistRange([lo, hi]) histogram domain
binSize(n) histogram bin width
site(slot) which display quadrant hosts the histogram ("00", "01", "10", "11")
stocStats(Graph, "Legend") track the named series of the named graph across runs, plotting mean and mean ± standard deviation over time
stocStatsTitle(text) statistics graph title

Multiple histograms. Flat stocHist… directives describe the first histogram; each nested bracket group adds another, with its own datum, bins, and slot:

StocPlatform #= [stocRuns(500),
    [stocHist("Harvested"), stocHistTitle("Harvested"), binSize(5)],
    [stocHist(quitTime), stocHistTitle("Extinction Time"), site("01")]
]

The directive names FreqGraph, FreqGraphTitle, FreqGraphRange and HistGraph, HistGraphTitle, HistGraphRange are accepted aliases of the stocHist family found in some presets.

4. Recording variables without a graph

Both platforms can observe a quantity that no visible display shows. The synthetic display target TimeSeries("name") records a series without occupying a dashboard quadrant:

update(TotNewInf) @= TimeSeries("TotNewInf")
…
StocPlatform #= [stocHist("TotNewInf"), …]

When sensTarget names an unquoted model variable, or stocHist names a quoted variable that no update routes and no legend matches, the code normalizer inserts this statement for you (numlTransformer.js); writing it explicitly keeps the program self-documenting.

5. quitWhen and quitTime

quitWhen @= condition ends a run early (model logic); quitTime is the time at which that happened. Together they turn the stochastic platform into a first-passage-time analyzer — the Population Viability preset records an extinction-time distribution:

next(N) @= Math.max(0, Total_Pre_Harvest - Harvested)
…
quitWhen @= (N <= 0)

StocPlatform #= [
    stocHist(quitTime),
    stocHistTitle("Extinction Time Histogram"),
    stocRuns(1000)
]

Runs that never satisfy quitWhen end at maxTime, so the histogram's last bin collects the non-extinct replicates. quitTime is only meaningful to stocHist; it is not a model value and cannot be a sensitivity target.

6. Worked configurations

Complete, runnable programs combining these pieces ship as presets:

Study Preset File
Parameter sweep of a continuous SIR (sensTarget(I), sensParam(Beta)) SIR dynss2.json
Stochastic epidemic with vaccination/treatment; histogram of total infections plus a mean ± std series Ex 20: Stochastic SIR model dynsshs.json
Harvested-population viability: sensitivity to harvest rate and an extinction-time histogram via quitWhen/quitTime Ex 13 Population Viability with Harvesting dynsshs.json

Each preset also carries its generated documentation, visible in the app's RAM documentation window when the preset is selected.