RandomKey

interface RandomKey : Wrappable<RandomKey>

A functional interface for generating random numbers. See also the paper "Splittable pseudorandom number generators using cryptographic hashing" by Claessen and Palka (https://publications.lib.chalmers.se/records/fulltext/183348/local_183348.pdf). A given RandomKey should be used either for the split operation, or floats. Once it is used for one of these, the given RandomKey instance should be discarded, as it would only generate the same values again. By default, a RandomKey will throw an exception if you try to use it for more than one operation. To permit multiple uses of the same RandomKey instance, for example because you want deterministic results, call permitReuse and use its return value instead.

Types

Companion
Link copied to clipboard
object Companion

Functions

floats
Link copied to clipboard
open fun floats(n: Int): DTensor

Produce a fresh vector of the given length filled with random float values between 0 (inclusive) and 1 (exclusive). This method will always produce the same sequence of values for a given key.

abstract fun floats(shape: Shape): DTensor

Produce a fresh tensor of the given shape filled with uniformly distributed float values between 0 (inclusive) and 1 (exclusive). This method will always produce the same sequence of values for a given RandomKey instance.

gamma
Link copied to clipboard
abstract fun gamma(alpha: FloatTensor): DTensor

Produces a fresh tensor of samples from a gamma distribution, each with shape parameter from the corresponding value in the alpha parameter. This method will always produce the same sequence of values for a given RandomKey instance.

gaussian
Link copied to clipboard
abstract fun gaussian(shape: Shape): DTensor

Produce a fresh tensor of the given shape filled with normally distributed float values with a mean of 0 and standard deviation of 1. This method will always produce the same sequence of values for a given RandomKey instance.

permitReuse
Link copied to clipboard
abstract fun permitReuse(): RandomKey

Return a RandomKey just like this one, except that the newly returned instance permits repeated calls to split and floats.

split
Link copied to clipboard
abstract fun split(n: Int = 2): List<RandomKey>

Split this random key into a new set of distinct and statistically independent keys.

wrap
Link copied to clipboard
open override fun wrap(wrapper: Wrapper): RandomKey

Wrap random key

Inheritors

TracingRandomKey
Link copied to clipboard
SplitRandom
Link copied to clipboard

Extensions

cauchy
Link copied to clipboard
fun RandomKey.cauchy(shape: Shape): DTensor

Samples from a cauchy distribution with a loc of 1 and a scale of 0 The cumulative distribution function (CDF) is F = (1 / 𝜋) arctan((x - loc) / scale) + (1 / 2) The random variable Y = F(x) has a uniform distribution. Therefore, we can invert F and use a uniform distribution to simulate random variable X https://en.wikipedia.org/wiki/Cauchy_distribution

fun RandomKey.cauchy(shape: Shape, loc: DTensor, scale: DTensor): DTensor

Samples from a cauchy distribution with loc and scale

chiSquare
Link copied to clipboard
fun RandomKey.chiSquare(shape: Shape, dof: DTensor): DTensor

Samples from a chi square distribution The chi square distribution X is a special case of the gamma distribution X ~ Gamma(dof / 2, 1 / 2) https://en.wikipedia.org/wiki/Chi-squared_distribution

gamma
Link copied to clipboard
fun RandomKey.gamma(shape: Shape, alpha: DTensor): DTensor

Samples from a gamma distribution with a shape parameter alpha (also known as k) and a scale/ rate parameter of 1

gammaWithRate
Link copied to clipboard
fun RandomKey.gammaWithRate(shape: Shape, alpha: DTensor, beta: DTensor): DTensor

Gamma distribution with a shape parameter alpha, which is equal to k, and a rate parameter β = 1/θ

gammaWithScale
Link copied to clipboard
fun RandomKey.gammaWithScale(shape: Shape, k: DTensor, theta: DTensor): DTensor

Gamma distribution with a shape parameter k, which is equal to alpha, and a scale parameter θ.

gaussian
Link copied to clipboard
fun RandomKey.gaussian(shape: Shape, mean: DTensor, std: DTensor): DTensor

Samples from a gaussian distribution with mean and std (standard deviation)