JSPM

  • Created
  • Published
  • Downloads 622
  • Score
    100M100P100Q83752F
  • License MIT

Distributions and random sampling.

Package Exports

  • essy-distribution

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (essy-distribution) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Javascript Distributions and Sampling

Installation

npm install essy-distribution

Description

Defines multiple distributions with methods for random sampling and calculating distribution properties. Sampling functions are largely ported from CERN's cern.jet.random Java package. See the source code for details.

This package was created during the development of Essy Tree to support Monte Carlo simulations.

Basic Usage (node.js)

var dists  = require('essy-distribution');

var normal = new dists.Normal(0, 1);
var mean   = normal.mean();     // 0
var sample = normal.sample();   // eg, 0.2314311234

Basic Usage (ES2015)

import { Normal } from 'essy-distribution';

var normal = new Normal(0, 1);
var mean   = normal.mean();     // 0
var sample = normal.sample();   // eg, 0.2314311234

Or you can load the entire package:

import * as dists from 'essy-distribution';

var normal = new dists.Normal(0, 1);
var mean   = normal.mean();     // 0
var sample = normal.sample();   // eg, 0.2314311234

Each distribution defines the following methods:

cdf(x {Number})

Cumulative distribution function.

mean()

Returns distribution mean.

median()

Returns distribution median.

pdf(x {Number})

Probability density function.

sample([n {Number}] [,generator {Object}])

Samples the distribution. If no arguments are provided or n = 1 a single sampled value is returned. If n is greater than 1, an array of n sampled values is returned.

The method accepts an optional generator object that defines a method random(). If no generator is provided a mersenne-twister is used.

variance()

Returns variance.

Distributions

Beta(alpha, beta)

See documentation.

Binomial(samples, probability)

See documentation.

Cauchy(location, scale)

See article.

ChiSquared(degreesOfFreedom)

See article.

Custom(values)

A custom distribution. The values argument should be an array of numbers.

Erlang(shape, rate)

See documentation. Does not define median().

Exponential(lambda)

See documentation.

F(degreesOfFreedom1, degreesOfFreedom2)

See article.

Gamma(shape, scale)

See documentation. Does not define median().

Hypergeometric(N, K, n)

See article.

Laplace(location, scale)

See documentation.

Logarithmic(probability)

See documentation. Does not define median().

Logistic(mean, scale)

See documentation.

LogLogistic(scale, shape)

See documentation.

LogNormal(mean, se)

See documentation.

Normal(mean, se)

See documentation.

Pareto(scale, shape)

See article.

Poisson(lambda)

See documentation.

Rayleigh(scale)

See documentation.

StudentT(degreesOfFreedom)

See article.

Triangular(min, mode, max)

See documentation.

Uniform(min, max)

See documentation.

Weibull(shape, scale)

See documentation.

SampleStat

The SampleStat class provides basic statistics from an array of sampled values.

var dists  = require('essy-distribution');
var sample = new dists.SampleStat([1, 2, 3, 4, 5]);

var mean   = sample.mean();   // 3
var median = sample.median(); // 3

SampleStat(values)

Create a new instance from an array of numerical values.

kurtosis()

Returns kurtosis of sample values.

max()

Returns maximum value in samples.

mean()

Returns mean of sample values.

median()

Returns median of sample values.

percentile(x)

Returns specified percentile where x is a value in the sample set range.

quantile(p)

Returns specified quantile, where p is in range [0, 1].

range()

Returns range of sample values.

skew()

Returns skewness of sample values.

stdDev()

Returns standard deviation of sample values.

variance()

Returns variance of sample values.