Skip to content

rikkhill/wonky

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wonky

Rejection sampling for common probability distributions in JavaScript.

Note to time-travellers from the future: this is old, but I keep it around because I like it. It is not how anyone writes javascript any more

I have occasionally needed values sampled from a specific distribution in JavaScript, but haven't found any lightweight libraries for doing this. wonky.js implements rejection sampling for common probability distributions (including various members of the natural exponential family, for which inverse transform sampling won't work).

Currently implemented distributions:

  • Normal
  • Poisson
  • Binomial
  • Beta
  • Gamma
  • Exponential

Example usage:

// Standard normal
normDist = Dist.N(0, 1)
// 10 random samples from standard normal
sample = normDist.sample(10)

// Binomial distribution, 10 trials, p=0.5
binomDist = Dist.B(10, 0.5)
// Sample once
successes = binomDist(1)

About

Probability distribution sampling in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published