/** * Distribution Objects * * Each factory function returns an object with .pdf(x), .cdf(x), * .quantile(p), .mean, .variance, .sample() and .sampleN(n, opts?) methods. * * Supported distributions: * - normalDist, betaDist, binomialDist, chiSquaredDist * - exponentialDist, fDist, gammaDist, logNormalDist * - poissonDist, tDist, uniformDist, weibullDist * * Worker dispatch (Slice 5.12): * - `.sampleN(n, opts?)` routes to workers via `sampleChunk` kernel when * `n >= DIST_WORKER_THRESHOLD` (100 000). * - Supports five distributions with worker paths: normalDist, gammaDist, * betaDist, tDist, exponentialDist. * - Below threshold (or for distributions without a worker kernel), falls back * to a synchronous JS loop. * - Seed splitting: chunk k uses seed `(baseSeed ^ (k * 0x9E3779B9)) >>> 0` * (SplitMix64-style Fibonacci hashing — gives uncorrelated chunk streams * even when baseSeed is 0 or small). * * @packageDocumentation */ /** 64-bit float (default for decimals) */ type f64 = number; /** * Minimum sample count that triggers the worker-dispatch path in `.sampleN()`. * Below this threshold, `.sampleN()` falls back to a synchronous JS loop. */ export declare const DIST_WORKER_THRESHOLD = 100000; /** * Options for batch sampling via `.sampleN()`. */ export interface SampleNOptions { /** * Integer seed for the Mulberry32 PRNG used within each worker chunk. * When omitted, a random seed is chosen (non-reproducible). */ seed?: number; /** * Number of worker tasks to fan out when `n >= DIST_WORKER_THRESHOLD`. * Defaults to the pool's `maxWorkers` setting. Set to 1 to use the * worker path with a single task (useful for testing the async code path). */ workerCount?: number; } /** * A probability distribution object with common statistical methods. */ export interface Distribution { /** Probability density (or mass) function */ pdf: (x: f64) => f64; /** Cumulative distribution function */ cdf: (x: f64) => f64; /** Quantile (inverse CDF) function */ quantile: (p: f64) => f64; /** Distribution mean */ mean: f64; /** Distribution variance */ variance: f64; /** Generate a single random sample (synchronous) */ sample: () => f64; /** * Generate `n` random samples. * * - When `n < DIST_WORKER_THRESHOLD` returns a plain `Float64Array` * synchronously (wrapped in a resolved Promise for a uniform call-site). * - When `n >= DIST_WORKER_THRESHOLD` **and** the distribution supports * the worker kernel, fans out across workers asynchronously. * - For distributions without a dedicated worker kernel (binomialDist, * chiSquaredDist, etc.) always uses the JS loop regardless of `n`. */ sampleN: (n: number, opts?: SampleNOptions) => Promise; } /** * Create a normal (Gaussian) distribution object. * * @param mu - Mean (default 0) * @param sigma - Standard deviation (default 1, must be positive) * @returns Distribution object * * @example * const d = normalDist(0, 1); * d.pdf(0) // ~0.3989 * d.cdf(0) // 0.5 * d.quantile(0.975) // ~1.96 */ export declare function normalDist(mu?: f64, sigma?: f64): Distribution; /** * Create a Beta distribution object. * * @param alpha - Shape parameter alpha > 0 * @param beta_ - Shape parameter beta > 0 * @returns Distribution object * * @example * const d = betaDist(2, 5); * d.mean // 2/7 */ export declare function betaDist(alpha: f64, beta_: f64): Distribution; /** * Create a Binomial distribution object. * * @param n - Number of trials (positive integer) * @param p - Success probability (0 <= p <= 1) * @returns Distribution object * * @example * const d = binomialDist(10, 0.5); * d.mean // 5 */ export declare function binomialDist(n: number, p: f64): Distribution; /** * Create a Chi-squared distribution object. * * @param k - Degrees of freedom (positive integer) * @returns Distribution object * * @example * const d = chiSquaredDist(3); * d.mean // 3 */ export declare function chiSquaredDist(k: number): Distribution; /** * Create an Exponential distribution object. * * @param lambda - Rate parameter (positive) * @returns Distribution object * * @example * const d = exponentialDist(2); * d.mean // 0.5 */ export declare function exponentialDist(lambda?: f64): Distribution; /** * Create an F-distribution object. * * @param d1 - Numerator degrees of freedom (positive) * @param d2 - Denominator degrees of freedom (positive) * @returns Distribution object * * @example * const d = fDist(5, 10); * d.mean // 10 / (10 - 2) = 1.25 */ export declare function fDist(d1: f64, d2: f64): Distribution; /** * Create a Gamma distribution object. * * @param shape - Shape parameter (positive) * @param rate - Rate parameter (positive, default 1) * @returns Distribution object * * @example * const d = gammaDist(2, 1); * d.mean // 2 */ export declare function gammaDist(shape: f64, rate?: f64): Distribution; /** * Create a Log-Normal distribution object. * * @param mu - Mean of the log (default 0) * @param sigma - Standard deviation of the log (default 1, positive) * @returns Distribution object * * @example * const d = logNormalDist(0, 1); * d.mean // e^0.5 */ export declare function logNormalDist(mu?: f64, sigma?: f64): Distribution; /** * Create a Poisson distribution object. * * @param lambda - Rate parameter (positive) * @returns Distribution object * * @example * const d = poissonDist(5); * d.mean // 5 */ export declare function poissonDist(lambda: f64): Distribution; /** * Create a Student's t-distribution object. * * @param nu - Degrees of freedom (positive) * @returns Distribution object * * @example * const d = tDist(10); * d.mean // 0 */ export declare function tDist(nu: f64): Distribution; /** * Create a Uniform distribution object. * * @param a - Lower bound (default 0) * @param b - Upper bound (default 1, must be > a) * @returns Distribution object * * @example * const d = uniformDist(0, 10); * d.mean // 5 */ export declare function uniformDist(a?: f64, b?: f64): Distribution; /** * Create a Weibull distribution object. * * @param k - Shape parameter (positive) * @param lambda - Scale parameter (positive, default 1) * @returns Distribution object * * @example * const d = weibullDist(2, 1); * d.mean // sqrt(pi) / 2 */ export declare function weibullDist(k: f64, lambda?: f64): Distribution; /** * Hypergeometric distribution — the number of successes in `draws` samples drawn * WITHOUT replacement from a `population` containing `successes` successes. * `hypergeometricDist(population, successes, draws)` matches * `scipy.stats.hypergeom(M=population, n=successes, N=draws)`. * * @example hypergeometricDist(50, 5, 10).pmf(1) // 0.4313371972 */ export declare function hypergeometricDist(population: number, successes: number, draws: number): Distribution; /** * Negative-binomial distribution — the number of failures before the `r`-th * success in i.i.d. Bernoulli(`p`) trials. `negativeBinomialDist(r, p)` matches * `scipy.stats.nbinom(r, p)` (integer `r`). * * @example negativeBinomialDist(5, 0.4).pmf(3) // 0.0774144 */ export declare function negativeBinomialDist(r: number, p: f64): Distribution; /** * Pareto distribution (shape `b` > 0, scale `xm` > 0) — `scipy.stats.pareto(b, scale=xm)`. * @example paretoDist(3, 2).cdf(4) // 0.875 */ export declare function paretoDist(b: number, xm: number): Distribution; /** * Rayleigh distribution (scale `sigma` > 0) — `scipy.stats.rayleigh(scale=sigma)`. * @example rayleighDist(2).mean // 2.5066282746 */ export declare function rayleighDist(sigma: number): Distribution; /** * Triangular distribution on `[a, b]` with mode `c` — matches * `scipy.stats.triang((c-a)/(b-a), loc=a, scale=b-a)`. * @example triangularDist(0, 4, 6).mean // 3.3333333333 */ export declare function triangularDist(a: number, c: number, b: number): Distribution; /** * Discrete uniform distribution on the integers `lo..hi` (inclusive) — matches * `scipy.stats.randint(lo, hi+1)`. * @example discreteUniformDist(1, 6).pmf(3) // 0.1666666667 */ export declare function discreteUniformDist(lo: number, hi: number): Distribution; /** * Gumbel (right / maximum) distribution (location `mu`, scale `beta` > 0) — * `scipy.stats.gumbel_r(loc=mu, scale=beta)`. * @example gumbelDist(1, 2).cdf(3) // 0.6922006276 */ export declare function gumbelDist(mu: number, beta: number): Distribution; /** * Inverse-Gaussian (Wald) distribution — mean `mu` > 0, shape `lambda` > 0. * Matches `scipy.stats.invgauss(mu, scale=lambda)` where the scipy mean is * `mu*scale`; here `mu` is the actual mean directly. * @example invGaussDist(1, 1).pdf(1) // 0.3989422804 */ export declare function invGaussDist(mu: number, lambda: number): Distribution; /** A multivariate distribution exposing a density function. */ export interface MultivariateDistribution { pdf: (x: number[]) => f64; mean: number[]; cov: number[][]; } /** * Multivariate normal distribution with the given `mean` vector and `cov` * covariance matrix. Density via a Cholesky factorization (stable log-det + * triangular solve). Matches `scipy.stats.multivariate_normal(mean, cov).pdf`. * * @example multivariateNormal([0, 0], [[1, 0.5],[0.5, 2]]).pdf([0, 0]) // 0.1203098284 */ export declare function multivariateNormal(mean: number[], cov: number[][]): MultivariateDistribution; export {}; //# sourceMappingURL=dist-objects.d.ts.map