randomvariate

package module
v0.0.0-...-b9c3294 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2017 License: Apache-2.0 Imports: 2 Imported by: 2

README

randomvariate

Build Status Coverage Status

Generate random numbers based on a probability distribution.

Currently supported probability distributions:

  • binomial
  • multinomial
  • Poisson

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Binomial

func Binomial(n int, p float64) int

Binomial draws n samples from a binomial probability distribution given by the probability p. Another way to imagine this is that the function counts the number of sucessful draws. If n = 1, the function draws once and the result can either be 1 or 0. The probability of successfully drawing is given by the slice p.

func Multinomial

func Multinomial(n int, p []float64) []int

Multinomial draws n samples from a probability distribution given by the set of probabilities p. Uses the inversion method which may be inefficient when the number of categories and number of samples are both large.

func MultinomialA

func MultinomialA(n int, p []float64) []int

MultinomialA draws n samples from a probability distribution given by the set of probabilities p. Uses the alias method. Faster when dealing with a larger number of categories and number of samples.

func MultinomialLog

func MultinomialLog(n int, logP []float64) []int

MultinomialLog draws n samples from a log-probability distribution given by the set of probabilities p. Note that the log probabilities are in the format log(p) where p is from 0 to 1. If p = 0, the log-probability should be encoded as negative infinity.

func MultinomialLog1p

func MultinomialLog1p(n int, logP []float64) []int

MultinomialLog1p draws n samples from a log-probability distribution given by the set of probabilities p. Note that the log probabilities are actually log(1+p) where p is from 0 to 1. This prevents solves the problem of computing log probability of 0.

func Poisson

func Poisson(lambda float64) int

func PoissonXL

func PoissonXL(lambda float64) int

func Round

func Round(x float64, e int) float64

Round rounds a value from zero based on the given units place. For example, the value to be round is 0.05 and the given unit is 0.1, Round will return 0.1 as it rounds 0.05 to the nearest tenths place.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL