functionpoissonDistribution({ mean }:PoissonDistributionParameters):PoissonDistribution
Construct a Poisson count distribution. Mean zero gives a point mass at zero.
Draws consume two 32-bit words for mean below 10, including zero,
and a variable number for transformed rejection at or above mean 10.
@throws ― {DistributionInvalidInputError} With INVALID_PARAMETER for an unsupported mean.
poissonDistribution } from'knotkit/distribution'
import {
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in
This generator is not cryptographically secure. Use crypto.getRandomValues()
when unpredictability matters.
@param ― seed - Initial seed, coerced to a signed 32-bit integer.
@returns ― A stateful function that returns the next value in the range [0, 1).
splitmix32 } from'knotkit/prng'
const
constcalls:PoissonDistribution
calls=
functionpoissonDistribution({ mean }:PoissonDistributionParameters):PoissonDistribution
Construct a Poisson count distribution. Mean zero gives a point mass at zero.
Draws consume two 32-bit words for mean below 10, including zero,
and a variable number for transformed rejection at or above mean 10.
@throws ― {DistributionInvalidInputError} With INVALID_PARAMETER for an unsupported mean.
poissonDistribution({
PoissonDistributionParameters.mean: number
Expected count, from zero through POISSON_MAX_MEAN.
mean: 3 })
const
constatMostFive:Probability
atMostFive=
constcalls:PoissonDistribution
calls.
CumulativeDistribution<"poisson", PoissonDistributionParameters>.cumulativeProbability: (x:number) => Probability
The probability of an outcome at or below x.
@throws ― {DistributionInvalidInputError} With INVALID_ARGUMENT when x is NaN or not a number.
cumulativeProbability(5)
const
constfirstCutoff:number
firstCutoff=
constcalls:PoissonDistribution
calls.
CumulativeDistribution<"poisson", PoissonDistributionParameters>.quantile: (p:Probability) => number
The first support value whose cumulative probability reaches p. At 0 and 1, returns the support endpoints.
@throws ― {DistributionInvalidInputError} With INVALID_PROBABILITY when p is outside [0, 1] or is NaN.
quantile(
constatMostFive:Probability
atMostFive)
const
constpercentile95:number
percentile95=
constcalls:PoissonDistribution
calls.
CumulativeDistribution<"poisson", PoissonDistributionParameters>.quantile: (p:Probability) => number
The first support value whose cumulative probability reaches p. At 0 and 1, returns the support endpoints.
@throws ― {DistributionInvalidInputError} With INVALID_PROBABILITY when p is outside [0, 1] or is NaN.
quantile(
constProbability: {
readonlymake: (value:number) =>Probability;
}
A number in the closed unit interval, checked by
Probability.make
.
Checked constructor for the opaque
Probability
scalar.
Probability.
make: (value:number) => Probability
@throws ― {DistributionInvalidInputError} With INVALID_PROBABILITY outside the closed unit interval.
make(0.95))
const
constnextCount:number
nextCount=
constcalls:PoissonDistribution
calls.
CumulativeDistribution<"poisson", PoissonDistributionParameters>.draw: (random:RandomSource) => number
Draw one value from the supplied source. There is no state between draws besides the caller's source.
The same seed replays on the same engine build and platform. One differing comparison or rounding on another
engine can change that draw and every later one, including how many words a rejection sampler consumes.
@throws ― {PrngInvalidInputError} With INVALID_SOURCE_VALUE for an invalid value from the source.
draw(
functionsplitmix32(seed:number): () =>number
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the
search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in
Every error this module throws is DistributionInvalidInputError, with a code from a closed, exported list. Branch on the code; the message is for people.
Measured by the suite in packages/distribution/__tests__/bench. The numbers come from one machine, so run the suite on yours before deciding on speed alone.
Use knotkit/distribution for this task. If Knotkit is missing, follow https://knotkit.jkomyno.dev/getting-started.md#install-from-source. Import from 'knotkit/distribution'.
Exports:
- `poissonDistribution` → `PoissonDistribution`: A nonnegative finite mean defines the distribution.
- `binomialDistribution` → `BinomialDistribution`: Construct successProbability with Probability.make.
- `geometricDistribution` → `GeometricDistribution`: Construct successProbability with Probability.make.
- `hypergeometricDistribution` → `HypergeometricDistribution`: Population, success count and sample size fix the distribution.
- `normalDistribution` → `NormalDistribution`: Location and standard deviation define the real-valued distribution.
- `logNormalDistribution` → `LogNormalDistribution`: Parameters describe the natural logarithm of the quantity.
- `gammaDistribution` → `GammaDistribution`: Rate is the reciprocal of scale.
- `exponentialDistribution` → `ExponentialDistribution`: Rate is the reciprocal of the mean.
- `chiSquaredDistribution` → `ChiSquaredDistribution`: Degrees of freedom determine the shape.
- `betaDistribution` → `BetaDistribution`: Alpha and beta define the bounded distribution.
- `studentTDistribution` → `StudentTDistribution`: Degrees of freedom define the heavy-tailed real-valued distribution.
- `fDistribution` → `FDistribution`: Numerator and denominator degrees of freedom define the nonnegative ratio distribution.
- `uniformDistribution` → `UniformDistribution`: Two ordered finite bounds define the interval.
- `probabilityTableDistribution` → `ProbabilityTableDistribution`: Construct the probability array with Probability.make.
- `customDiscreteDistribution` → `CustomDiscreteDistribution`: Evaluates a caller-provided mass function.
- `customContinuousDistribution` → `CustomContinuousDistribution`: Uses an optional caller-supplied survival function and quantile.
- `sampleMean` → `number`: Running arithmetic mean of a finite sample.
- `sampleVariance` → `number`: Welford variance; degreesOfFreedomCorrection defaults to 1.
- `median` → `number`: Exact median of a sorted copy.
- `sampleQuantile` → `number`: Type 7 linear-interpolation quantile of a sorted copy.
- `histogram` → `Histogram`: Counts per half-open bin, last bin closed, as np.histogram.
- `covariance` → `number`: Welford co-moment covariance; degreesOfFreedomCorrection defaults to 1.
- `pearsonCorrelation` → `number`: Product-moment correlation clamped to [-1, 1].
Pick the layout by these rules:
- `poissonDistribution` (kind 'poisson') when The quantity is a count of independent events at a known mean rate.
- `binomialDistribution` (kind 'binomial') when The quantity is successes in a fixed number of independent trials with one success probability.
- `geometricDistribution` (kind 'geometric') when The quantity is failures before the first success in independent trials.
- `hypergeometricDistribution` (kind 'hypergeometric') when The quantity is successes in a sample drawn without replacement from a finite population.
- `normalDistribution` (kind 'normal') when The quantity is modeled as a symmetric bell-shaped real value.
- `logNormalDistribution` (kind 'log-normal') when The quantity is positive and its natural logarithm follows a normal distribution.
- `gammaDistribution` (kind 'gamma') when The quantity is a positive waiting time with a known gamma shape and rate.
- `exponentialDistribution` (kind 'exponential') when The quantity is a memoryless waiting time at a known rate.
- `chiSquaredDistribution` (kind 'chi-squared') when The quantity is a sum of squared standard normals or a chi-squared test statistic.
- `betaDistribution` (kind 'beta') when The quantity is a continuous proportion on the unit interval with two shape parameters.
- `studentTDistribution` (kind 'student-t') when The quantity is a standardized mean of a normal sample whose variance is estimated, or a real value with heavier tails than normal.
- `fDistribution` (kind 'f') when The quantity is a ratio of two independent chi-squared variables each divided by its degrees of freedom, such as a variance ratio or ANOVA statistic.
- `uniformDistribution` (kind 'uniform') when The quantity is equally dense throughout a finite interval.
- `probabilityTableDistribution` (kind 'probability-table') when The caller has an ordered table of finite values with explicit masses.
- `customDiscreteDistribution` (kind 'custom-discrete') when The caller supplies a mass function over integer outcomes and a CDF for unbounded upper support.
- `customContinuousDistribution` (kind 'custom-continuous') when The caller supplies the density and CDF for a continuous distribution over an interval.
Inputs and their sources:
- randomness per draw: `RandomSource` from `knotkit/prng`
- probability callbacks for custom distributions: `CustomDiscreteDistributionParameters or CustomContinuousDistributionParameters` from `caller`
Use something else when:
- shuffle or sample from an array → knotkit/sampling
- fit a distribution's parameters to data → SciPy or R
- test whether draws fit a distribution → knotkit/hypothesis-test
- evaluate a multivariate distribution → SciPy or R
Errors are DistributionInvalidInputError with a `code` property. Branch on `error.code`, never on the message.
Full page: https://knotkit.jkomyno.dev/modules/distribution.md
Types: node_modules/knotkit/distribution/ and https://knotkit.jkomyno.dev/reference/knotkit/distribution/