Probability Functions (12)

Probability functions, random numbers, combinatorial counting

bernoulli
The nth Bernoulli number
Syntax
bernoulli(n)
Parameters
NameTypeDescription
nnumber | BigNumber | bigint | Fraction
Returns
number | BigNumber | Fraction —
Examples
bernoulli(4)
bernoulli(fraction(12))
combinations
Compute the number of combinations of n items taken k at a time
Syntax
combinations(n | k)
Type Signatures
BigNumber, BigNumber
Parameters
NameTypeDescription
nnumber | BigNumberTotal number of objects in the set
knumber | BigNumberNumber of objects in the subset
Returns
number | BigNumber — Number of possible combinations.
Examples
combinations(7
5)
combinationsWithRep
Compute the number of combinations of n items taken k at a time with replacements.
Syntax
combinationsWithRep(n | k)
Type Signatures
number, number, BigNumber, BigNumber
Parameters
NameTypeDescription
nnumber | BigNumberTotal number of objects in the set
knumber | BigNumberNumber of objects in the subset
Returns
number | BigNumber — Number of possible combinations with replacement.
Examples
combinationsWithRep(7
5)
factorial
Compute the factorial of a value
Syntax
n! | factorial(n)
Parameters
NameTypeDescription
nnumber | BigNumber | Array | MatrixAn integer number
Returns
number | BigNumber | Array | Matrix — The factorial of `n`
Examples
5!
5 * 4 * 3 * 2 * 1
3!
gamma
Compute the gamma function. For small values, the Lanczos approximation is used, and for large values the extended Stirling approximation.
Syntax
gamma(n)
Parameters
NameTypeDescription
nnumber | BigNumber | ComplexA real or complex number
Returns
number | BigNumber | Complex — The gamma of `n`
Examples
gamma(4)
3!
gamma(1/2)
sqrt(pi)
See Also
factorial
kldivergence
Calculate the Kullback-Leibler (KL) divergence between two distributions.
Syntax
kldivergence(x | y)
Type Signatures
Array, Array, Matrix, Array, Array, Matrix, Matrix, Matrix
Parameters
NameTypeDescription
qArray | MatrixFirst vector
pArray | MatrixSecond vector
Returns
number — Returns distance between q and p
Examples
kldivergence([0.7
0.5
0.4
See Also
lgamma
Logarithm of the gamma function for real, positive numbers and complex numbers,
Syntax
lgamma(n)
Examples
lgamma(4)
lgamma(1/2)
lgamma(i)
lgamma(complex(1.1
2))
See Also
gamma
multinomial
Multinomial Coefficients compute the number of ways of picking a1, a2, ..., ai unordered outcomes from `n` possibilities. multinomial takes one array of integers as an argument. The following condition must be enforced: every ai > 0.
Syntax
multinomial(A)
Type Signatures
Array | Matrix
Parameters
NameTypeDescription
anumber[] | BigNumber[]Integer numbers of objects in the subset
Returns
Number | BigNumber — Multinomial coefficient.
Examples
multinomial([1
2
1
permutations
Compute the number of permutations of n items taken k at a time
Syntax
permutations(n) | permutations(n | k)
Type Signatures
number, number, BigNumber, BigNumber
Parameters
NameTypeDescription
nnumber | BigNumberThe number of objects in total
knumber | BigNumberThe number of objects in the subset
Returns
number | BigNumber — The number of permutations
Examples
permutations(5)
permutations(5
3)
pickRandom
Pick a random entry from a given array.
Syntax
pickRandom(array) | pickRandom(array | number)
Type Signatures
Array | Matrix, Array | Matrix, Object, Array | Matrix, number, Array | Matrix, Array | Matrix, Array | Matrix, Array | Matrix, number, Array | Matrix, number, Array | Matrix
Parameters
NameTypeDescription
arrayArray | MatrixA one dimensional array
numberIntAn int or float
weightsArray | MatrixAn array of ints or floats
Returns
number | Array — Returns a single random value from array when number is undefined.
Examples
pickRandom(0:10)
pickRandom([1
3
1
6
See Also
random randomInt
random
Return a random number.
Syntax
random() | random(max) | random(min
Parameters
NameTypeDescription
sizeArray | MatrixIf provided, an array or matrix with given
minnumberMinimum boundary for the random value, included
maxnumberMaximum boundary for the random value, excluded
Returns
number | Array | Matrix — A random number
Examples
random()
random(10
20)
random([2
3
randomInt
Return a random integer number
Syntax
randomInt(max) | randomInt(min | max)
Parameters
NameTypeDescription
sizeArray | MatrixIf provided, an array or matrix with given
minnumberMinimum boundary for the random value, included
maxnumberMaximum boundary for the random value, excluded
Returns
number | Array | Matrix — A random integer value
Examples
randomInt(10
20)
randomInt([2
3
See Also
pickRandom random