# input_uncertainty

Python reference for `nagasim.uncertainty.input_uncertainty`.

`nagasim.uncertainty.input_uncertainty`

```python
input_uncertainty(layout, inputs: list[dict], kpis: list[str] | None = None, resamples: int = 20, replications: int = 5, seed: int = 0, run_length: float | None = None, warmup: float | None = None, workers: int | str = 1, should_stop = None, overrides: list[dict] | None = None)
```

Each KPI's run-to-run interval, its interval with the inputs' uncertainty, and the
inputs' share of the spread.

Parameters
----------
layout : dict or str
    The model.
inputs : list of dict
    ``{"path", "values"}`` per input: a ``...distribution`` path takes a sample, a
    ``schedules.<name>.points`` path takes arrival timestamps plus ``bin_width`` and
    ``cycle`` in base time units.
kpis : list of str, optional
    `experiments.flatten_kpis` keys; default every ``system/`` KPI.
resamples, replications : int
    Bootstrap resamples (at least 2) and replications per model (at least 2); the
    model runs ``(resamples + 1) x replications`` times, at most `MAX_RUNS`.
seed : int
    Replication r of every run uses ``seed + r``; the resampling draws from
    ``inputfit.bootstrap_rng(seed)``, a stream of its own.
overrides : list of dict, optional
    A change (``{"path", "value"}``, as `what_if` takes it): every KPI row is then the
    changed model minus the baseline, both run per resample on the same seeds, and the
    run count doubles. Applied after the resample's inputs, so an override of an input
    path wins.

Returns
-------
dict
    ``{"completed", "measure": "level" | "difference", "overrides" (None for a
    level), "resamples", "resamples_used", "failed": {path: count},
    "replications", "runs", "seed", "inputs", "kpis": [{"kpi", "mean", "run_ci",
    "input_interval", "input_share", "resamples_used"}], "notes"}``. Raises
    ValueError for a request it cannot answer (ModelValidationError for a path the
    model does not have), before any run; and when fewer than half the resamples
    (at least 2) could be refitted.

See Also
--------
nagasim.inputfit.best_fit : Fits the distribution a sample comes from.
nagasim.experiments.run_scenarios : Compares scenarios without input uncertainty.
input_uncertainty_frame : The same answer as a DataFrame, one row per KPI.

Examples
--------
>>> import random
>>> from nagasim import build as nb, uncertainty
>>> m = nb.Model(time_limit=300, warmup=30)
>>> m.add_resource(name="Server", capacity=1)
'Server'
>>> arrive = m.create("arrive", distribution=nb.Exponential(rate=0.9))
>>> _ = arrive >> m.process("serve", resource_name="Server",
...                         distribution=nb.Exponential(rate=1.0)) >> m.dispose()
>>> rng = random.Random(0)
>>> gaps = [round(rng.expovariate(0.9), 3) for _ in range(30)]
>>> out = uncertainty.input_uncertainty(
...     m.to_dict(), [{"path": "blocks.arrive.params.distribution", "values": gaps}],
...     kpis=["system/Total Entities Completed"], resamples=2, replications=2)
>>> out["runs"], out["completed"]
(6, True)
>>> sorted(out["kpis"][0])
['input_interval', 'input_share', 'kpi', 'mean', 'resamples_used', 'run_ci']
