Input sources: cimba.inputs
from cimba import inputs. Every function here returns an immutable
source to bind to an Input or Series field. Sources are
configuration only; they never appear in model code. All parameters are
keyword-only unless shown otherwise.
Distributions: inputs.dist
Drawn inside the trial on the input’s own random stream. Never exhausted.
Numeric parameters may be cimba.sweep() objects (or sweep.map(...));
fixed values are validated when the source is built, swept values when the
experiment is created.
Every constructor accepts keyword-only tag: str | None = None. A tag
replaces the input’s tree path when deriving its random stream, preserving
draws across renames and moves. Equal tags intentionally share a stream
identity; the default retains path-based seeding.
Function |
Distribution |
|---|---|
|
Exponential with the given mean (not rate). |
|
Sum of |
|
Sum of exponentials with the given means (positional list). |
|
Mixture of exponentials (positional lists). |
|
Gamma; mean |
|
Weibull. |
|
|
|
Normal. |
|
Logistic. |
|
Cauchy. |
|
Location-scale Student t. |
|
Chi-squared. |
|
|
|
Rayleigh. |
|
Pareto with minimum |
|
Continuous uniform. |
|
Triangular. |
|
PERT (scaled beta, weight 4). |
|
Modified PERT with custom weight. |
|
Beta scaled to |
|
1 with probability |
|
Binomial. |
|
Trials until first success (≥ 1). |
|
Failures before |
|
Poisson. |
|
Integer uniform on |
|
|
Integer-valued distributions work well with cb.Input[int].
Recorded data
- cimba.inputs.trace(data, *, on_exhausted='fail')
Replay a 1-D array exactly as recorded.
datais copied and fingerprinted (SHA-256).on_exhaustedis"fail","wrap"or"end_trial".
Bootstrap resampling: inputs.bootstrap
Generated on the host once per replication from a stream derived from the replication seed and the input’s identity. All are prefix-stable and extend transparently.
- bootstrap.iid(data)
Independent draws with replacement. Keeps the marginal distribution and drops autocorrelation.
- bootstrap.moving_block(data, *, block)
Concatenate random blocks of
blockconsecutive values.
- bootstrap.circular_block(data, *, block)
Like
moving_block, but blocks may wrap around the end of the data.
- bootstrap.stationary(data, *, mean_block)
Stationary bootstrap: blocks of geometrically distributed length with mean
mean_block, wrapping around. The resampled series is stationary.
- bootstrap.joint(panel, *, mean_block, tag=None)
Stationary bootstrap of several equal-length series that uses the same blocks for every member, preserving cross-correlation.
panelis a mapping or a sequence of 1-D arrays. Index the result like the panel,joint[key], to get each member’s source. Iterating yields the keys.
- bootstrap.intermittent(data, *, jitter=False)
For intermittent series (mostly zeros): a two-state Markov chain for occurrence, fitted to the data, with sizes resampled from the nonzero values.
jitter=Trueperturbs sizes. Needs at least two nonzero values and one zero.
Fitted time-series models: inputs.fitted
These separate deterministic structure (trend and season) from the residuals, and generate new series as structure plus resampled or modelled residuals. Common arguments:
trendPolynomial degree of the trend (
0constant,1linear, …),Nonefor the mean, or"auto"to choose among 0, 1 and 2 by AICc.periodSeason length in samples,
Nonefor no season, or"auto"to detect one from the periodogram. With a period, structure comes from an STL decomposition (robust=Truefor robust STL); beyond the data, the season repeats and the trend extrapolates linearly.startIndex in the reference series where generated rows begin.
nonnegativeClip generated values at zero (demand, counts).
- fitted.residual(data, *, trend=1, period=None, mean_block=None, start=0, nonnegative=False, robust=False)
Structure plus residuals resampled iid, or with a stationary bootstrap if
mean_blockis given.
- fitted.wild(data, *, trend=1, period=None, weights='rademacher', start=0, nonnegative=False, robust=False)
Wild bootstrap: structure plus each in-sample residual multiplied by a random weight (
"rademacher","mammen"or"normal"). Keeps heteroscedasticity. Limited tolen(data) - startvalues, and fails rather than extends beyond that.
- fitted.sieve(data, *, order=None, trend=None, period=None, start=0, nonnegative=False, robust=False)
Sieve bootstrap: fit an AR(
order) model to the residuals (order chosen by AIC whenNone) and regenerate them from resampled innovations. Needs at least eight observations.
- fitted.intermittent(data, *, jitter=False)
Same as
bootstrap.intermittent().
Fitting distributions
- cimba.inputs.fit(data, candidates=None)
Fit candidate distributions by maximum likelihood and return a tuple of
FitResult, best (lowest AIC) first. The default candidates aredist.exponential,dist.gamma,dist.lognormal,dist.normalanddist.weibull. Candidates the data can’t support (for example non-positive values for a gamma) are skipped.
Custom sources
- cimba.inputs.row_source(method, data, draw, *, parameters=None, tag=None, prefix_stable=True, max_length=None, length_hint=None, on_exhausted='extend')
Build a row source from
draw(rng, length) -> array. See Write a custom input source for the contract.
- cimba.inputs.trace_rng(seed, tag)
The
numpy.random.GeneratorCimba would pass to a row source withtagfor a trial seed. Useful for testing prefix stability.
Source objects
All sources have describe() -> dict (versioned provenance) and an
on_exhausted attribute.
- class cimba.inputs.DistributionSource
method,parametersand optionaltag. Built byinputs.dist.*.
- class cimba.inputs.GeneratedRows
A row source.
generate(rngs, length)returns a(len(rngs), length)array; also hasprefix_stable,max_length,length_hintandtag. Built by the bootstrap, fitted androw_source()functions.
- class cimba.inputs.RowSource
The protocol
GeneratedRowsimplements.
- class cimba.inputs.Source
The protocol every source implements.
- exception cimba.inputs.InputError
Raised for invalid source parameters or data, and for generators that return malformed rows.