GitHub
deepbox/random

Distributions & Sampling

Continuous and discrete sampling utilities, categorical helpers, multivariate draws, and shuffling primitives.
Sampling
uniform
export declare function uniform(low?: number, high?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from continuous uniform distribution.

normal
export declare function normal(mean?: number, std?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from normal (Gaussian) distribution.

binomial
export declare function binomial(n: number, p: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from binomial distribution.

poisson
export declare function poisson(lambda: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from Poisson distribution.

exponential
export declare function exponential(scale?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from exponential distribution.

gamma
export declare function gamma(shape_param: number, scale?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from gamma distribution.

beta
export declare function beta(alpha: number, beta_param: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from beta distribution.

choice
export declare function choice(a: Tensor | number, size?: number | Shape, replace?: boolean, p?: Tensor): Tensor;

Random sample from array.

shuffle
export declare function shuffle(x: Tensor): void;

Randomly shuffle array in-place.

permutation
export declare function permutation(x: Tensor | number): Tensor;

Return random permutation of array.

multinomial
export declare function multinomial(n: number, pvals: Tensor, size?: number): Tensor;

Draw samples from a multinomial distribution.

multivariate_normal
export declare function multivariate_normal(mean: Tensor, cov: Tensor, size?: number): Tensor;

Draw samples from a multivariate normal distribution.

dirichlet
export declare function dirichlet(alpha: Tensor, size?: number): Tensor;

Draw samples from a Dirichlet distribution.

categorical
export declare function categorical(probs: Tensor, numSamples?: number, replacement?: boolean): Tensor;

Sample from a categorical distribution.

gumbel_softmax
export declare function gumbel_softmax(logits: Tensor, tau?: number, hard?: boolean): Tensor;

Sample from a categorical distribution using the Gumbel-Softmax trick.

bernoulli
export declare function bernoulli(p: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from Bernoulli distribution.

geometric
export declare function geometric(p: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from geometric distribution.

lognormal
export declare function lognormal(mean?: number, std?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from log-normal distribution.

chi2
export declare function chi2(df: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from chi-squared distribution.

student_t
export declare function student_t(df: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from Student's t distribution.

f_distribution
export declare function f_distribution(dfn: number, dfd: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from F distribution.

laplace
export declare function laplace(loc?: number, scale?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from Laplace distribution.

cauchy
export declare function cauchy(loc?: number, scale?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from Cauchy distribution.

weibull
export declare function weibull(shape_param: number, scale?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from Weibull distribution.

triangular
export declare function triangular(left: number, mode: number, right: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from triangular distribution.

negative_binomial
export declare function negative_binomial(r: number, p: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from negative binomial distribution.

hypergeometric
export declare function hypergeometric(ngood: number, nbad: number, nsample: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from hypergeometric distribution.

vonmises
export declare function vonmises(mu: number, kappa: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from the von Mises distribution (circular normal).

pareto
export declare function pareto(alpha: number, xm?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from the Pareto (Type I) distribution.

rayleigh
export declare function rayleigh(sigma?: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from the Rayleigh distribution.

zipf
export declare function zipf(s: number, shape?: Shape, opts?: RandomOptions): Tensor;

Random samples from the Zipf (zeta) distribution.

random-distributions.ts
import {  beta,  choice,  dirichlet,  normal,  permutation,  poisson,  shuffle,  uniform,} from "deepbox/random";import { tensor } from "deepbox/ndarray";console.log(uniform(-1, 1, [3]).toString());console.log(normal(0, 1, [3]).toString());console.log(poisson(3, [5]).toString());console.log(beta(2, 5, [5]).toString());console.log(choice(tensor([10, 20, 30]), 2).toString());console.log(permutation(5).toString());console.log(dirichlet(tensor([1, 1, 1]), 2).toString());const shuffled = tensor([1, 2, 3, 4]);shuffle(shuffled);console.log(shuffled.toString());