# dist

package
Version: v1.0.0 Latest Latest

Go to latest
Published: Aug 4, 2020 License: MIT

## Documentation ¶

### Overview ¶

Package dist provides statistical probability distributions for random variables.

### Constants ¶

View Source
```const (
NaN    = 0x7FF8000000000001
Inf    = 0x7FF0000000000000
NegInf = 0xFFF0000000000000
)```

Nabbed these from math...

### Variables ¶

This section is empty.

### Functions ¶

#### func PDF ¶

`func PDF(d DistP, a, b float64) (p float64)`

PDF returns the probability that a value lands between a and b, where a <= b.

### Types ¶

#### type Binomial ¶

```type Binomial struct {
// contains filtered or unexported fields
}```

Binomial distribution with parameter n and p.

TODO.

#### type Continuous ¶

```type Continuous interface {
Float64() float64
}```

#### func Highpass ¶

`func Highpass(c Continuous, low float64) Continuous`

#### func Lowpass ¶

`func Lowpass(c Continuous, high float64) Continuous`

#### func Midpass ¶

`func Midpass(c Continuous, low, high float64) Continuous`

#### type Discrete ¶

```type Discrete interface {
Int63() int64
}```

#### func Ceil ¶

`func Ceil(c Continuous) Discrete`

#### func Floor ¶

`func Floor(c Continuous) Discrete`

#### func Round ¶

`func Round(c Continuous) Discrete`

#### type Dist ¶

```type Dist interface {
DistP

// Q returns the p-quantile of the distribution, this is the inverse CDF function.
Q(p float64) (x float64)
}```

Dist is implemented by all distributions that give the inverse CDF function. Because this is not possible for all distributions, it remains optional.

#### type DistP ¶

```type DistP interface {
// Name of the distribution
String() string

// P returns the probability that a value from the distribution is less than x.
// That is, P represents the cumulative probability function of the distribution.
P(x float64) (p float64)
}```

#### type Exponential ¶

```type Exponential struct {
// contains filtered or unexported fields
}```

Exponential distribution with rate of arrival.

#### func NewExponential ¶

`func NewExponential(s rand.Source, lambda float64) *Exponential`

#### func (*Exponential) Float64 ¶

`func (e *Exponential) Float64() float64`

#### func (*Exponential) Mean ¶

`func (e *Exponential) Mean() float64`

#### func (*Exponential) P ¶

`func (e *Exponential) P(x float64) float64`

#### func (*Exponential) Q ¶

`func (e *Exponential) Q(p float64) float64`

#### func (*Exponential) String ¶

`func (e *Exponential) String() string`

#### type HyperExponential ¶

```type HyperExponential struct {
// contains filtered or unexported fields
}```

HyperExponential distribution with k rates of arrival.

#### func NewHyperExponential ¶

`func NewHyperExponential(s rand.Source, probs, lambdas []float64) *HyperExponential`

#### func (*HyperExponential) Float64 ¶

`func (e *HyperExponential) Float64() float64`

#### func (*HyperExponential) Mean ¶

`func (e *HyperExponential) Mean() float64`

#### func (*HyperExponential) SecondMoment ¶

`func (e *HyperExponential) SecondMoment() float64`

#### func (*HyperExponential) String ¶

`func (e *HyperExponential) String() string`

#### func (*HyperExponential) Var ¶

`func (e *HyperExponential) Var() float64`

#### type LogNormal ¶

```type LogNormal struct {
// contains filtered or unexported fields
}```

LogNormal distribution with mean and standard deviation.

See:

```http://stackoverflow.com/questions/23699738
http://blogs.sas.com/content/iml/2014/06/04/simulate-lognormal-data-with-specified-mean-and-variance.html
```

#### func NewLogNormal ¶

`func NewLogNormal(rs rand.Source, m, s float64) *LogNormal`

#### func (*LogNormal) Float64 ¶

`func (n *LogNormal) Float64() float64`

#### func (*LogNormal) Mean ¶

`func (n *LogNormal) Mean() float64`

#### func (*LogNormal) Std ¶

`func (n *LogNormal) Std() float64`

#### func (*LogNormal) String ¶

`func (n *LogNormal) String() string`

#### func (*LogNormal) Var ¶

`func (n *LogNormal) Var() float64`

#### func (*LogNormal) Z ¶

`func (n *LogNormal) Z(x float64) float64`

#### type Normal ¶

```type Normal struct {
// contains filtered or unexported fields
}```

Normal distribution with mean and standard deviation.

#### func NewNormal ¶

`func NewNormal(s rand.Source, mean, std float64) *Normal`

#### func (*Normal) Float64 ¶

`func (n *Normal) Float64() float64`

#### func (*Normal) Mean ¶

`func (n *Normal) Mean() float64`

#### func (*Normal) Std ¶

`func (n *Normal) Std() float64`

#### func (*Normal) String ¶

`func (n *Normal) String() string`

#### func (*Normal) Var ¶

`func (n *Normal) Var() float64`

#### func (*Normal) Z ¶

`func (n *Normal) Z(x float64) float64`

#### type Null ¶

`type Null struct{}`

#### func NewNull ¶

`func NewNull() *Null`

#### func (Null) Float64 ¶

`func (n Null) Float64() float64`

#### func (Null) Int63 ¶

`func (n Null) Int63() int64`

#### func (Null) Mean ¶

`func (n Null) Mean() float64`

#### func (Null) Std ¶

`func (n Null) Std() float64`

#### func (Null) String ¶

`func (n Null) String() string`

#### func (Null) Var ¶

`func (n Null) Var() float64`

#### type Poisson ¶

```type Poisson struct {
// contains filtered or unexported fields
}```

Poisson returns random numbers according to a poisson distribution.

The poisson distribution models the number of arrivals in a set time interval when the inter-arrival times are exponentially distributed. This is why

#### func NewPoisson ¶

`func NewPoisson(s rand.Source, lambda float64) *Poisson`

#### func (Poisson) Int63 ¶

`func (p Poisson) Int63() int64`

#### func (Poisson) Mean ¶

`func (p Poisson) Mean() float64`

#### func (Poisson) String ¶

`func (p Poisson) String() string`

#### func (Poisson) Var ¶

`func (p Poisson) Var() float64`

#### type Stairs ¶

```type Stairs struct {
// contains filtered or unexported fields
}```

Stairs returns the index of the first probability value that exceeds the random value between 0.0 and 1.0.

For example, given the following list:

```[0.0, 0.3, 0.6, 0.6, 0.9]
```

We can imagine the following stairs, with indices from 0 to 4.

```                    .
.____.____|
.____|
.____|
0   0.3  0.6  0.6  0.9
0    1    2    3    4
```

The probability for index 0 and 3 is 0.0. The probability for the rest is is the value minus the previous divided by the last value in the list, in this case 0.9. The indices 1, 2, and 4 all have the same probability then. Therefore, we get the same result if we pass in the list:

```[0, 3, 6, 6, 9]
```

The only requirement on the numbers in the list are that they are monotonically increasing. Failing this requirement will cause NewStairs to panic.

#### func NewStairs ¶

`func NewStairs(s rand.Source, p ...float64) *Stairs`

#### func (*Stairs) Int63 ¶

`func (s *Stairs) Int63() int64`

#### func (*Stairs) Mean ¶

`func (s *Stairs) Mean() float64`

#### func (*Stairs) P ¶

`func (s *Stairs) P(x int64) (p float64)`

#### func (*Stairs) Q ¶

`func (s *Stairs) Q(p float64) (x float64)`

#### func (*Stairs) String ¶

`func (s *Stairs) String() string`

#### type Uniform ¶

```type Uniform struct {
// contains filtered or unexported fields
}```

Uniform gives a uniform distribution between a and b.

#### func NewUniform ¶

`func NewUniform(s rand.Source, a, b float64) *Uniform`

#### func (*Uniform) Float64 ¶

`func (u *Uniform) Float64() float64`

#### func (*Uniform) Mean ¶

`func (u *Uniform) Mean() float64`

#### func (*Uniform) P ¶

`func (u *Uniform) P(x float64) (p float64)`

#### func (*Uniform) Q ¶

`func (u *Uniform) Q(p float64) (x float64)`

#### func (*Uniform) String ¶

`func (u *Uniform) String() string`

#### type UniformDiscrete ¶

```type UniformDiscrete struct {
// contains filtered or unexported fields
}```

UniformDiscrete gives a discrete uniform distribution between a and b.

#### func NewUniformDiscrete ¶

`func NewUniformDiscrete(s rand.Source, a, b int64) *UniformDiscrete`

NewUniformDiscrete returns a discrete uniform distribution in [a, b). Note: this will not work if (b-a) is greater than 2**63.

#### func (*UniformDiscrete) Int63 ¶

`func (u *UniformDiscrete) Int63() int64`

#### func (*UniformDiscrete) Mean ¶

`func (u *UniformDiscrete) Mean() float64`

#### func (*UniformDiscrete) P ¶

`func (u *UniformDiscrete) P(x int64) (p float64)`

#### func (*UniformDiscrete) Q ¶

`func (u *UniformDiscrete) Q(p float64) (x float64)`

#### func (*UniformDiscrete) String ¶

`func (u *UniformDiscrete) String() string`