5.8 KiB
sidebar_position | title |
---|---|
2 | Distribution |
Main
mixture
(...distributionLike, weights:list<float>):distribution
Examples
mixture(normal(5, 1), normal(10, 1));
sample
Get one random sample from the distribution
(distribution):number
Examples
sample(normal(5, 2));
sampleN
Get n random samples from the distribution
(distribution, number):list<number>
Examples
sample(normal(5, 2), 100);
mean
Get the distribution mean
(distribution):number
Examples
mean(normal(5, 2));
stdev
(distribution):number
variance
(distribution):number
mode
(distribution):number
cdf
(distribution, number):number
Examples
cdf(normal(5, 2), 3);
(distribution, number):number
Examples
pdf(normal(5, 2), 3);
pmf
(distribution, number):number
Examples
pmf(bernoulli(0.3), 0); // 0.7
inv
(distribution, number):number
Examples
inv(normal(5, 2), 0.5);
toPointSet
Converts a distribution to the pointSet format
(distribution):pointSetDistribution
Examples
toPointSet(normal(5, 2));
toSampleSet
Converts a distribution to the sampleSet format, with n samples
(distribution,n):sampleSetribution
Examples
toSampleSet(normal(5, 2));
truncateLeft
Truncates the left side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
(distribution, l:number, {normalize: boolean=true}):distribution
Examples
truncateLeft(normal(5, 2), 3);
truncateRight
Truncates the right side of a distribution. Returns either a pointSet distribution or a symbolic distribution.
(distribution, r:number, {normalize: boolean=true}):distribution
Examples
truncateLeft(normal(5, 2), 6);
klDivergence
Kullback–Leibler divergence between two distributions
(distribution, distribution):number
Examples
klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57
logScore
({estimate: distribution, prior?: distribution, answer: distribution|number}):number
Examples
logScore({ estimate: normal(5, 2), prior: normal(5.5, 4), answer: 2.3 });
toString
(distribution):string
Examples
toString(normal(5, 2));
toSparkline
Produce a sparkline of length n
(distribution, n=20):string
Examples
toSparkline(normal(5, 2), 10);
inspect
Prints the value of the distribution to the Javascript console, then returns the distribution.
(distribution):distribution
Examples
inspect(normal(5, 2));
normalize
Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1.
(distribution):distribution
Examples
normalize(normal(5, 2));
isNormalized
Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions.
(distribution):bool
Examples
isNormalized(normal(5, 2)); // returns true
integralSum
Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1.
(distribution):number
Examples
integralSum(normal(5, 2));
add
(distributionLike, distributionLike): distribution
sum
(list<distributionLike>): distribution
multiply
(distributionLike, distributionLike): distribution
product
(list<distributionLike>): distribution
subtract
(distributionLike, distributionLike): distribution
divide
(distributionLike, distributionLike): distribution
pow
(distributionLike, distributionLike): distribution
exp
(distributionLike, distributionLike): distribution
log
(distributionLike, distributionLike): distribution
log10
(distributionLike, distributionLike):distribution
unaryMinus
(distribution):distribution
dotAdd
(distributionLike, distributionLike): distribution
dotSum
(list<distributionLike>): distribution
dotMultiply
(distributionLike, distributionLike): distribution
dotProduct
(list<distributionLike>): distribution
dotSubtract
(distributionLike, distributionLike): distribution
dotDivide
(distributionLike, distributionLike): distribution
dotPow
(distributionLike, distributionLike): distribution
dotExp
(distributionLike, distributionLike): distribution
scaleMultiply
(distributionLike, distributionLike): distribution
scalePow
(distributionLike, distributionLike): distribution
scaleExp
(distributionLike, distributionLike): distribution
scaleLog
(distributionLike, distributionLike): distribution
scaleLog10
(distributionLike, distributionLike): distribution
scaleLogWithThreshold
(distributionLike, distributionLike, number): distribution