Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discrete-sampling

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discrete-sampling

JavaScript for sampling from a handful of discrete probability distributions

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

sampling

JavaScript for sampling from a handful of discrete probability distributions

Setup

This is now a node module on npm. To install, go to your project's directory in a terminal and enter npm install discrete-sampling To load the library in your own node module, use

var SJS = Sampling = require('discrete-sampling');

To load the module in the browser, you can load the script with

<script src="node_modules/discrete-sampling/dist/discrete.js"></script>

and then the library will be accessible through the global variables SJS and Sampling.

Currently Supported

  • Bernoulli
  • Binomial
  • Discrete
  • Multinomial
  • Poisson
  • Negative Binomial

Examples

var bern = Sampling.Bernoulli(.5);
bern.draw();     // One random draw
bern.sample(10); // Get an array of 10 samples. 
var binom = SJS.Binomial(10, 0.5);  // alternate syntax (Sampling === SJS)
binom.draw();
binom.sample(10);
var probabilities = [.1, .2, .3, .05, .15];
var disc = SJS.Discrete(probabilities);
disc.draw(); 
disc.sample(10); 
// The probabilities will be normalized for you. 
var probs = [1,1,1,1,1,1,1,1,1,1,1,1,1,1]
var mult = SJS.Multinomial(5, probs);
mult.draw();
mult.sample(10);
var myArray = [0,1,2,3,4,5]
// sample five elements with replacement
sample_from_array(myArray, 5, true)
// sample five elements without replacement
sample_from_array(myArray, 5)

Keywords

FAQs

Package last updated on 15 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc