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(mean)

Exponential with the given mean (not rate).

erlang(k, mean)

Sum of k exponentials; overall mean.

hypoexponential(means)

Sum of exponentials with the given means (positional list).

hyperexponential(means, probabilities)

Mixture of exponentials (positional lists).

gamma(shape, scale=1.0)

Gamma; mean shape * scale.

weibull(shape, scale=1.0)

Weibull.

lognormal(mean=0.0, sigma=1.0)

exp(N(mean, sigma)): parameters of the underlying normal.

normal(mean=0.0, sd=1.0)

Normal.

logistic(mean=0.0, scale=1.0)

Logistic.

cauchy(mode=0.0, scale=1.0)

Cauchy.

student_t(df, mean=0.0, scale=1.0)

Location-scale Student t.

chi_squared(df)

Chi-squared.

f_dist(df1, df2)

rayleigh(scale)

Rayleigh.

pareto(shape, mode=1.0)

Pareto with minimum mode.

uniform(low=0.0, high=1.0)

Continuous uniform.

triangular(low, mode, high)

Triangular.

pert(low, mode, high)

PERT (scaled beta, weight 4).

pert_mod(low, mode, high, weight)

Modified PERT with custom weight.

beta(a, b, low=0.0, high=1.0)

Beta scaled to [low, high].

bernoulli(p)

1 with probability p, else 0.

binomial(n, p)

Binomial.

geometric(p)

Trials until first success (≥ 1).

negative_binomial(successes, p)

Failures before successes successes.

poisson(mean)

Poisson.

dice(low, high)

Integer uniform on low..high inclusive.

categorical(values, probabilities)

values[i] with probability probabilities[i] (positional lists, summing to 1).

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. data is copied and fingerprinted (SHA-256). on_exhausted is "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 block consecutive 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. panel is 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=True perturbs 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:

trend

Polynomial degree of the trend (0 constant, 1 linear, …), None for the mean, or "auto" to choose among 0, 1 and 2 by AICc.

period

Season length in samples, None for no season, or "auto" to detect one from the periodogram. With a period, structure comes from an STL decomposition (robust=True for robust STL); beyond the data, the season repeats and the trend extrapolates linearly.

start

Index in the reference series where generated rows begin.

nonnegative

Clip 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_block is 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 to len(data) - start values, 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 when None) 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 are dist.exponential, dist.gamma, dist.lognormal, dist.normal and dist.weibull. Candidates the data can’t support (for example non-positive values for a gamma) are skipped.

class cimba.inputs.FitResult
source

The fitted DistributionSource, ready to bind.

aic
ks

Kolmogorov–Smirnov distance between the data and the fit.

log_likelihood

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.Generator Cimba would pass to a row source with tag for 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, parameters and optional tag. Built by inputs.dist.*.

class cimba.inputs.TraceSource

values (read-only), fingerprint and on_exhausted. Built by trace().

class cimba.inputs.GeneratedRows

A row source. generate(rngs, length) returns a (len(rngs), length) array; also has prefix_stable, max_length, length_hint and tag. Built by the bootstrap, fitted and row_source() functions.

class cimba.inputs.RowSource

The protocol GeneratedRows implements.

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.