Documentation
¶
Overview ¶
Package rnd implements random numbers generators (wrapping the standard functions or the Mersenne Twister library). It also implements probability distribution functions.
Index ¶
- Variables
- func BuildTextHist(xmin, xmax float64, nstations int, values []float64, numfmt string, barlen int) string
- func FlipCoin(p float64) bool
- func Float64(low, high float64) float64
- func Float64s(values []float64, low, high float64)
- func FrechetPlotCoef(dirout, fnkey string, amin, amax float64)
- func HaltonPoints(dim, n int) (x [][]float64)
- func HypercubeCoords(sample [][]int, xmin, xmax []float64) (X [][]float64)
- func Init(seed int)
- func Int(low, high int) int
- func IntGetGroups(groups [][]int, pool []int)
- func IntGetShuffled(values []int) (shuffled []int)
- func IntGetUnique(values []int, n int) (selected []int)
- func IntGetUniqueN(start, endp1, n int) (selected []int)
- func IntShuffle(values []int)
- func Ints(values []int, low, high int)
- func LatinIHS(dim, n, d int) (x [][]int)
- func Lognormal(μ, σ float64) float64
- func MTfloat64(low, high float64) float64
- func MTfloat64s(values []float64, low, high float64)
- func MTinit(seed int)
- func MTint(low, high int) int
- func MTintShuffle(v []int)
- func MTints(values []int, low, high int)
- func Normal(μ, σ float64) float64
- func ReportVariables(dirout, fnkey string, sets SetsOfVars, genPDF bool)
- func Shuffle(values []float64)
- func StatAve(x []float64) (xave float64)
- func StatAveDev(x []float64, std bool) (xave, xdev float64)
- func StatBasic(x []float64, std bool) (xmin, xave, xmax, xdev float64)
- func StatDev(x []float64, std bool) (xdev float64)
- func StatDevFirst(x []float64, xave float64, std bool) (xdev float64)
- func StatDur(durs []time.Duration) (min, ave, max, sum time.Duration)
- func StatMoments(x []float64) (sum, mean, adev, sdev, vari, skew, kurt float64)
- func StatTable(x [][]float64, std, withZ bool) (y, z [][]float64)
- func StdInvPhi(x float64) float64
- func StdPhi(x float64) float64
- func Stdphi(x float64) float64
- func TextHist(labels []string, counts []int, barlen int) string
- func Uniform(min, max float64) float64
- func UnitVectors(n int) (U [][]float64)
- type DistFrechet
- type DistGumbel
- type DistLogNormal
- type DistNormal
- type DistUniform
- type Distribution
- type Histogram
- type IntHistogram
- type SetOfVars
- type SetsOfVars
- type Variable
- type Variables
Constants ¶
This section is empty.
Variables ¶
var ( // Primes1000 contains 1000 prime numbers Primes1000 = []int{}/* 1000 elements not displayed */ )
Functions ¶
func BuildTextHist ¶
func BuildTextHist(xmin, xmax float64, nstations int, values []float64, numfmt string, barlen int) string
BuildTextHist builds a text histogram
Input: xmin -- station xmin xmax -- station xmax nstations -- number of stations values -- values to be counted numfmt -- number format barlen -- max length of bar
func Float64 ¶
Float64 generates a pseudo random real number between low and high; i.e. in [low, right)
Input: low -- lower limit (closed) high -- upper limit (open) Output: random float64
func Float64s ¶
Float64s generates pseudo random real numbers between low and high; i.e. in [low, right)
Input: low -- lower limit (closed) high -- upper limit (open) Output: values -- slice to be filled with len(values) numbers
func FrechetPlotCoef ¶
FrechetPlotCoef plots coefficients for Frechet parameter's estimation
func HypercubeCoords ¶
HypercubeCoords computes the coordinates in the hypercube
Input: sample -- the hypercube sampling indices; e.g. from LatinIHS [ndim][npoints] xmin -- min limit of coordinates [ndim] xmax -- max limit of coordinates [ndim] Output: X -- coordinates [ndim][npoints]
func Init ¶
func Init(seed int)
Init initialises random numbers generators
Input: seed -- seed value; use seed <= 0 to use current time
func Int ¶
Int generates pseudo random integer between low and high.
Input: low -- lower limit high -- upper limit Output: random integer
func IntGetGroups ¶
IntGetGroups randomly selects indices from pool separating them in groups
Input: pool -- all ints. Output: groups -- [ngroups][size_of_group] pre-allocated slices
func IntGetShuffled ¶
IntGetShuffled returns a shufled slice of integers
func IntGetUnique ¶
IntGetUnique randomly selects n items in a list avoiding duplicates
Note: using the 'reservoir sampling' method; see Wikipedia: https://en.wikipedia.org/wiki/Reservoir_sampling
func IntGetUniqueN ¶
IntGetUniqueN randomly selects n items from start to endp1-1 avoiding duplicates
Note: using the 'reservoir sampling' method; see Wikipedia: https://en.wikipedia.org/wiki/Reservoir_sampling
func Ints ¶
Ints generates pseudo random integers between low and high.
Input: low -- lower limit high -- upper limit Output: values -- slice to be filled with len(values) numbers
func LatinIHS ¶
LatinIHS implements the improved distributed hypercube sampling algorithm. Note: code developed by John Burkardt (GNU LGPL license) -- see source code for further information.
Input: dim -- spatial dimension n -- number of points to be generated d -- duplication factor ≥ 1 (~ 5 is reasonable) Output: x -- [dim][n] points
func MTfloat64 ¶
MTfloat64 generates pseudo random real numbers between low and high; i.e. in [low, right) using the Mersenne Twister method.
Input: low -- lower limit (closed) high -- upper limit (open) Output: random float64
func MTfloat64s ¶
MTfloat64s generates pseudo random real numbers between low and high; i.e. in [low, right) using the Mersenne Twister method.
Input: low -- lower limit (closed) high -- upper limit (open) Output: values -- slice to be filled with len(values) numbers
func MTinit ¶
func MTinit(seed int)
MTinit initialises random numbers generators (Mersenne Twister code)
Input: seed -- seed value; use seed <= 0 to use current time
func MTint ¶
MTint generates pseudo random integer between low and high using the Mersenne Twister method.
Input: low -- lower limit high -- upper limit Output: random integer
func MTintShuffle ¶
func MTintShuffle(v []int)
MTintShuffle shuffles a slice of integers using Mersenne Twister algorithm.
func MTints ¶
MTints generates pseudo random integers between low and high using the Mersenne Twister method.
Input: low -- lower limit high -- upper limit Output: values -- slice to be filled with len(values) numbers
func ReportVariables ¶
func ReportVariables(dirout, fnkey string, sets SetsOfVars, genPDF bool)
ReportVariables generates TeX report of sets of variables
func StatAveDev ¶
StatAveDev computes the average of x and the average deviation or standard deviation (σ)
Input: x -- sample std -- compute standard deviation (σ) instead of average deviation (adev) Output: xdev -- average deviation; if std==true, computes standard deviation (σ) instead
func StatBasic ¶
StatBasic performs some basic statistics
Input: x -- sample std -- compute standard deviation (σ) instead of average deviation (adev) Output: xmin -- minimum value xave -- mean average (first moment) xmax -- maximum value xdev -- average deviation; if std==true, computes standard deviation (σ) instead
func StatDev ¶
StatDev computes the average deviation or standard deviation (σ)
Input: x -- sample std -- compute standard deviation (σ) instead of average deviation (adev) Output: xdev -- average deviation; if std==true, computes standard deviation (σ) instead
func StatDevFirst ¶
StatDevFirst computes the average deviation or standard deviation (σ) for given value of average/mean/first moment
Input: x -- sample xave -- bar(x) == average/mean/first moment std -- compute standard deviation (σ) instead of average deviation (adev) Output: xdev -- average deviation; if std==true, computes standard deviation (σ) instead
func StatMoments ¶
StatMoments computes the 4th moments of a data set
Input: x -- sample Output: sum -- sum of values mean -- mean average (first moment) adev -- average deviation sdev -- standrad deviation vari -- variance (second moment) skew -- skewness (third moment) kurt -- kurtosis (fourth moment) Based on: Press WH, Teukolsky SA, Vetterling WT and Flannery BP (2007) Numerical Recipes in C++ 2007 (3rd Edition), page 725.
func StatTable ¶
StatTable computes the min, ave, max, and dev of values organised in a table
Input: x -- sample std -- compute standard deviation (σ) instead of average deviation (adev) withZ -- computes z-matrix as well Convention of indices: 0=min 1=ave 2=max 3=dev Output: min ave max dev ↓ ↓ ↓ ↓ x00 x01 x02 x03 x04 x05 → y00=min(x0?) y10=ave(x0?) y20=max(x0?) y30=dev(x0?) x10 x11 x12 x13 x14 x15 → y01=min(x1?) y11=ave(x1?) y21=max(x1?) y31=dev(x1?) x20 x21 x22 x23 x24 x25 → y02=min(x2?) y12=ave(x2?) y22=max(x2?) y32=dev(x2?) ↓ ↓ ↓ ↓ min → z00=min(y0?) z01=min(y1?) z02=min(y2?) z03=min(y3?) ave → z10=ave(y0?) z11=ave(y1?) z12=ave(y2?) z13=ave(y3?) max → z20=max(y0?) z21=max(y1?) z22=max(y2?) z23=max(y3?) dev → z30=dev(y0?) z31=dev(y1?) z32=dev(y2?) z33=dev(y3?) = = = = min → z00=min(min) z01=min(ave) z02=min(max) z03=min(dev) ave → z10=ave(min) z11=ave(ave) z12=ave(max) z13=ave(dev) max → z20=max(min) z21=max(ave) z22=max(max) z23=max(dev) dev → z30=dev(min) z31=dev(ave) z32=dev(max) z33=dev(dev)
func UnitVectors ¶
UnitVectors generates random unit vectors in 3D
Types ¶
type DistFrechet ¶
type DistFrechet struct { L float64 // location. default = 0 C float64 // scale. default = 1 A float64 // shape }
DistFrechet implements the Frechet / Type II Extreme Value Distribution (largest value)
func (DistFrechet) Cdf ¶
func (o DistFrechet) Cdf(x float64) float64
Cdf computes the cumulative probability function @ x
func (*DistFrechet) Init ¶
func (o *DistFrechet) Init(p *Variable)
Init initialises Frechet distribution
func (*DistFrechet) Name ¶ added in v1.0.1
func (o *DistFrechet) Name() string
Name returns the name of this probability distribution
func (DistFrechet) Pdf ¶
func (o DistFrechet) Pdf(x float64) float64
Pdf computes the probability density function @ x
type DistGumbel ¶
type DistGumbel struct { U float64 // location: characteristic largest value B float64 // scale: measure of dispersion of the largest value }
DistGumbel implements the Gumbel / Type I Extreme Value Distribution (largest value)
func (DistGumbel) Cdf ¶
func (o DistGumbel) Cdf(x float64) float64
Cdf computes the cumulative probability function @ x
func (*DistGumbel) Init ¶
func (o *DistGumbel) Init(p *Variable)
Init initialises Gumbel distribution
func (*DistGumbel) Name ¶ added in v1.0.1
func (o *DistGumbel) Name() string
Name returns the name of this probability distribution
func (DistGumbel) Pdf ¶
func (o DistGumbel) Pdf(x float64) float64
Pdf computes the probability density function @ x
type DistLogNormal ¶
type DistLogNormal struct { // input N float64 // mean of log(x) Z float64 // standard deviation of log(x) // auxiliary A float64 // 1 / (z sqrt(2 π)) B float64 // -1 / (2 z²) }
DistLogNormal implements the lognormal distribution
func (*DistLogNormal) CalcDerived ¶
func (o *DistLogNormal) CalcDerived()
CalcDerived computes derived/auxiliary quantities
func (DistLogNormal) Cdf ¶
func (o DistLogNormal) Cdf(x float64) float64
Cdf computes the cumulative probability function @ x
func (*DistLogNormal) Init ¶
func (o *DistLogNormal) Init(p *Variable)
Init initialises lognormal distribution
func (*DistLogNormal) Name ¶ added in v1.0.1
func (o *DistLogNormal) Name() string
Name returns the name of this probability distribution
func (DistLogNormal) Pdf ¶
func (o DistLogNormal) Pdf(x float64) float64
Pdf computes the probability density function @ x
type DistNormal ¶
type DistNormal struct { // input Mu float64 // μ: mean Sig float64 // σ: std deviation // contains filtered or unexported fields }
DistNormal implements the normal distribution
func (*DistNormal) CalcDerived ¶
func (o *DistNormal) CalcDerived()
CalcDerived compute derived/auxiliary quantities
func (DistNormal) Cdf ¶
func (o DistNormal) Cdf(x float64) float64
Cdf computes the cumulative probability function @ x
func (*DistNormal) Init ¶
func (o *DistNormal) Init(p *Variable)
Init initialises normal distribution
func (*DistNormal) Name ¶ added in v1.0.1
func (o *DistNormal) Name() string
Name returns the name of this probability distribution
func (DistNormal) Pdf ¶
func (o DistNormal) Pdf(x float64) float64
Pdf computes the probability density function @ x
type DistUniform ¶
DistUniform implements the normal distribution
func (DistUniform) Cdf ¶
func (o DistUniform) Cdf(x float64) float64
Cdf computes the cumulative probability function @ x
func (*DistUniform) Init ¶
func (o *DistUniform) Init(p *Variable)
Init initialises uniform distribution
func (*DistUniform) Name ¶ added in v1.0.1
func (o *DistUniform) Name() string
Name returns the name of this probability distribution
func (DistUniform) Pdf ¶
func (o DistUniform) Pdf(x float64) float64
Pdf computes the probability density function @ x
type Distribution ¶
type Distribution interface { Name() string Init(prms *Variable) Pdf(x float64) float64 Cdf(x float64) float64 }
Distribution defines a probability distribution
func GetDistrib ¶
func GetDistrib(dtype string) (d Distribution)
GetDistrib returns a distribution from factory
type Histogram ¶
Histogram holds data for computing/plotting histograms
bin[i] corresponds to station[i] <= x < station[i+1] [ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] )[ bin[4] ) ---|---------|---------|---------|---------|---------|--- x s[0] s[1] s[2] s[3] s[4] s[5]
func (Histogram) DensityArea ¶
DensityArea computes the area of the density diagram
nsamples -- number of samples used when generating pseudo-random numbers
func (Histogram) PlotDensity ¶
PlotDensity plots histogram in density values
args -- plot arguments. may be nil
type IntHistogram ¶
IntHistogram holds data for computing/plotting histograms with integers
bin[i] corresponds to station[i] <= x < station[i+1] [ bin[0] )[ bin[1] )[ bin[2] )[ bin[3] )[ bin[4] ) ---|---------|---------|---------|---------|---------|--- x s[0] s[1] s[2] s[3] s[4] s[5]
func (*IntHistogram) Count ¶
func (o *IntHistogram) Count(vals []int, clear bool)
Count counts how many items fall within each bin
func (IntHistogram) FindBin ¶
func (o IntHistogram) FindBin(x int) int
FindBin finds where x falls in returns -1 if x is outside the range
func (IntHistogram) GenLabels ¶
func (o IntHistogram) GenLabels(numfmt string) (labels []string)
GenLabels generate nice labels identifying bins
type Variable ¶ added in v1.0.1
type Variable struct { // input: required by many distributions D string // [required] type of distribution M float64 // [optional] mean S float64 // [optional] standard deviation // input: Frechet L float64 // [Frechet] location C float64 // [Frechet] scale A float64 // [Frechet] shape // input: limits Min float64 // [optional] min value Max float64 // [optional] max value // optional Key string // [optional] auxiliary indentifier Prm *dbf.P // [optional] parameter connected to this random variable // derived Normal bool // [derived] is normal distribution Distr Distribution // [derived] pointer to distribution }
Variable holds all data defining a single random variable including information about a probability distribution that bests represents this variable
Some distributions: "N" : Normal "L" : Lognormal "G" : Gumbel (Type I Extreme Value) "F" : Frechet (Type II Extreme Value) "U" : Uniform
func (*Variable) SetDistribution ¶ added in v1.0.1
SetDistribution sets the implementation of Distribution in VarData