Package org.diffkt.random

Types

DiffktRandom
Link copied to clipboard
class DiffktRandom(randomKey: RandomKey) : Wrappable<DiffktRandom>
RandomKey
Link copied to clipboard
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.

Functions

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)