Documentation ¶
Overview ¶
Package godist provides a collection of useful continuous and discrete probability distributions, as well as helpful associated methods around them.
Index ¶
- type Beta
- type Distribution
- type Empirical
- func (e *Empirical) Add(values ...float64)
- func (e *Empirical) Float64() (float64, error)
- func (e *Empirical) Mean() (float64, error)
- func (e *Empirical) Median() (float64, error)
- func (e *Empirical) Mode() (float64, error)
- func (e *Empirical) Size() float64
- func (e *Empirical) Variance() (float64, error)
- type InvalidDistributionError
- type UnsupportedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Beta ¶
A Beta distribution is a continuous probability distribution on the range [0, 1], which can be formed using shape parameters α, β > 0.
Beta distributions have many uses, with one of the more common ones being to model random variables.
func (Beta) Float64 ¶
Float64 returns a random variate from the Beta Distribution.
Float64 makes use of four different algorithms for generating random variates, depending on the values of α and β. This implementation is based on the work done by Kevin Karplus in gen_beta.c (https://compbio.soe.ucsc.edu/gen_sequence/gen_beta.c)
func (Beta) Median ¶
Median returns the median of the Beta distribution.
Since there is no closed-form expression for the median of a Beta distribution, we use a number of known closed-form special cases, and an approximation for the general case where α > 1 and β > 1.
Currently, Median cannot calculate the median where α and β are < 1 unless α = β.
type Distribution ¶
type Distribution interface { Mean() (float64, error) Median() (float64, error) Mode() (float64, error) Variance() (float64, error) // generate a random value according to the probability distribution Float64() (float64, error) }
Distribution is the interface that defines useful methods for understanding specific instances of distributions, and sampling random variates from them.
type Empirical ¶
type Empirical struct {
// contains filtered or unexported fields
}
An Empirical distribution in the context of the godist package is essentially just a sample of discrete values.
All values added to an Empirical Distribution remain in memory, and while some efficiencies have been made around memoising certain values, in general calls to Median and Mode currently involve re-sorting the entire sample in the Empirical distribution.
func (*Empirical) Add ¶
Add adds one or more values to the empirical sample.
Add carries out some operations to improve the efficiency of other method calls, which is the main reason why the underlying sample data-structure is not exported.
func (*Empirical) Float64 ¶
Float64 returns a randomly sampled value from the Empirical distribution.
func (*Empirical) Median ¶
Median calculates the distribution median.
Median returns a memoised median if either: (1) the distribution has not been updated since the last call to Median, or (2) all values added to the distribution since the last call are equal to the median of the distribution.
In the case that the distribution sample size is even, the mean of the two middle values is returned.
func (*Empirical) Mode ¶
Mode calculates the distribution mode.
Mode returns a memoised if either: (1) the distribution has not been updated since the last call to Mode, or (2) all values added to the distribution since the last call are equal to the mode of the distribution.
In the case that the distribution is multi-modal, the smallest mode is returned.
type InvalidDistributionError ¶
type InvalidDistributionError struct{ S string }
func (InvalidDistributionError) Error ¶
func (e InvalidDistributionError) Error() string
type UnsupportedError ¶
type UnsupportedError struct{ S string }
func (UnsupportedError) Error ¶
func (e UnsupportedError) Error() string