distuv

package
v0.0.0-...-dfba71b Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package distuv provides univariate random distribution types.

Index

Examples

Constants

This section is empty.

Variables

View Source
var UnitNormal = Normal{Mu: 0, Sigma: 1}

UnitNormal is an instantiation of the normal distribution with Mu = 0 and Sigma = 1.

View Source
var UnitUniform = Uniform{Min: 0, Max: 1}

UnitUniform is an instantiation of the uniform distribution with Min = 0 and Max = 1.

Functions

This section is empty.

Types

type Bernoulli

type Bernoulli struct {
	P      float64
	Source *rand.Rand
}

Bernoulli represents a random variable whose value is 1 with probability p and value of zero with probability 1-P. The value of P must be between 0 and 1. More information at https://en.wikipedia.org/wiki/Bernoulli_distribution.

func (Bernoulli) CDF

func (b Bernoulli) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (Bernoulli) Entropy

func (b Bernoulli) Entropy() float64

Entropy returns the entropy of the distribution.

func (Bernoulli) ExKurtosis

func (b Bernoulli) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (Bernoulli) LogProb

func (b Bernoulli) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Bernoulli) Mean

func (b Bernoulli) Mean() float64

Mean returns the mean of the probability distribution.

func (Bernoulli) Median

func (b Bernoulli) Median() float64

Median returns the median of the probability distribution.

func (Bernoulli) NumParameters

func (Bernoulli) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Bernoulli) Prob

func (b Bernoulli) Prob(x float64) float64

Prob computes the value of the probability distribution at x.

func (Bernoulli) Quantile

func (b Bernoulli) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (Bernoulli) Rand

func (b Bernoulli) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Bernoulli) Skewness

func (b Bernoulli) Skewness() float64

Skewness returns the skewness of the distribution.

func (Bernoulli) StdDev

func (b Bernoulli) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Bernoulli) Survival

func (b Bernoulli) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (Bernoulli) Variance

func (b Bernoulli) Variance() float64

Variance returns the variance of the probability distribution.

type Beta

type Beta struct {
	// Alpha is the left shape parameter of the distribution. Alpha must be greater
	// than 0.
	Alpha float64
	// Beta is the right shape parameter of the distribution. Beta must be greater
	// than 0.
	Beta float64

	Source *rand.Rand
}

Beta implements the Beta distribution, a two-parameter continuous distribution with support between 0 and 1.

The beta distribution has density function

x^(α-1) * (1-x)^(β-1) * Γ(α+β) / (Γ(α)*Γ(β))

For more information, see https://en.wikipedia.org/wiki/Beta_distribution

func (Beta) CDF

func (b Beta) CDF(x float64) float64

CDF computes the value of the cumulative distribution function at x.

func (Beta) ExKurtosis

func (b Beta) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (Beta) LogProb

func (b Beta) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Beta) Mean

func (b Beta) Mean() float64

Mean returns the mean of the probability distribution.

func (Beta) Mode

func (b Beta) Mode() float64

Mode returns the mode of the distribution.

Mode returns NaN if either parameter is less than or equal to 1 as a special case.

func (Beta) NumParameters

func (b Beta) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Beta) Prob

func (b Beta) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Beta) Quantile

func (b Beta) Quantile(p float64) float64

Quantile returns the inverse of the cumulative distribution function.

func (Beta) Rand

func (b Beta) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Beta) StdDev

func (b Beta) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Beta) Survival

func (b Beta) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (Beta) Variance

func (b Beta) Variance() float64

Variance returns the variance of the probability distribution.

type Categorical

type Categorical struct {
	// contains filtered or unexported fields
}

Categorical is an extension of the Bernouilli distribution where x takes values {0, 1, ..., len(w)-1} where w is the weight vector. Categorical must be initialized with NewCategorical.

func NewCategorical

func NewCategorical(w []float64, src *rand.Rand) Categorical

NewCategorical constructs a new categorical distribution where the probability that x equals i is proportional to w[i]. All of the weights must be nonnegative, and at least one of the weights must be positive.

func (Categorical) CDF

func (c Categorical) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (Categorical) Entropy

func (c Categorical) Entropy() float64

Entropy returns the entropy of the distribution.

func (Categorical) Len

func (c Categorical) Len() int

Len returns the number of values x could possibly take (the length of the initial supplied weight vector).

func (Categorical) LogProb

func (c Categorical) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Categorical) Mean

func (c Categorical) Mean() float64

Mean returns the mean of the probability distribution.

func (Categorical) Prob

func (c Categorical) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Categorical) Rand

func (c Categorical) Rand() float64

Rand returns a random draw from the categorical distribution.

func (Categorical) Reweight

func (c Categorical) Reweight(idx int, w float64)

Reweight sets the weight of item idx to w. The input weight must be non-negative, and after reweighting at least one of the weights must be positive.

func (Categorical) ReweightAll

func (c Categorical) ReweightAll(w []float64)

ReweightAll resets the weights of the distribution. ReweightAll panics if len(w) != c.Len. All of the weights must be nonnegative, and at least one of the weights must be positive.

type ChiSquared

type ChiSquared struct {
	// K is the shape parameter, corresponding to the degrees of freedom. Must
	// be greater than 0.
	K float64

	Src *rand.Rand
}

ChiSquared implements the χ² distribution, a one parameter distribution with support on the positive numbers.

The density function is given by

1/(2^{k/2} * Γ(k/2)) * x^{k/2 - 1} * e^{-x/2}

It is a special case of the Gamma distribution, Γ(k/2, 1/2).

For more information, see https://en.wikipedia.org/wiki/Chi-squared_distribution.

func (ChiSquared) CDF

func (c ChiSquared) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (ChiSquared) ExKurtosis

func (c ChiSquared) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (ChiSquared) LogProb

func (c ChiSquared) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (ChiSquared) Mean

func (c ChiSquared) Mean() float64

Mean returns the mean of the probability distribution.

func (ChiSquared) Mode

func (c ChiSquared) Mode() float64

Mode returns the mode of the distribution.

func (ChiSquared) NumParameters

func (c ChiSquared) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (ChiSquared) Prob

func (c ChiSquared) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (ChiSquared) Quantile

func (c ChiSquared) Quantile(p float64) float64

Quantile returns the inverse of the cumulative distribution function.

func (ChiSquared) Rand

func (c ChiSquared) Rand() float64

Rand returns a random sample drawn from the distribution.

func (ChiSquared) StdDev

func (c ChiSquared) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (ChiSquared) Survival

func (c ChiSquared) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (ChiSquared) Variance

func (c ChiSquared) Variance() float64

Variance returns the variance of the probability distribution.

type Exponential

type Exponential struct {
	Rate   float64
	Source *rand.Rand
}

Exponential represents the exponential distribution (https://en.wikipedia.org/wiki/Exponential_distribution).

func (Exponential) CDF

func (e Exponential) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (*Exponential) ConjugateUpdate

func (e *Exponential) ConjugateUpdate(suffStat []float64, nSamples float64, priorStrength []float64)

ConjugateUpdate updates the parameters of the distribution from the sufficient statistics of a set of samples. The sufficient statistics, suffStat, have been observed with nSamples observations. The prior values of the distribution are those currently in the distribution, and have been observed with priorStrength samples.

For the exponential distribution, the sufficient statistic is the inverse of the mean of the samples. The prior is having seen priorStrength[0] samples with inverse mean Exponential.Rate As a result of this function, Exponential.Rate is updated based on the weighted samples, and priorStrength is modified to include the new number of samples observed.

This function panics if len(suffStat) != 1 or len(priorStrength) != 1.

func (Exponential) Entropy

func (e Exponential) Entropy() float64

Entropy returns the entropy of the distribution.

func (Exponential) ExKurtosis

func (Exponential) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (*Exponential) Fit

func (e *Exponential) Fit(samples, weights []float64)

Fit sets the parameters of the probability distribution from the data samples x with relative weights w. If weights is nil, then all the weights are 1. If weights is not nil, then the len(weights) must equal len(samples).

func (Exponential) LogProb

func (e Exponential) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Exponential) Mean

func (e Exponential) Mean() float64

Mean returns the mean of the probability distribution.

func (Exponential) Median

func (e Exponential) Median() float64

Median returns the median of the probability distribution.

func (Exponential) Mode

func (Exponential) Mode() float64

Mode returns the mode of the probability distribution.

func (Exponential) NumParameters

func (Exponential) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Exponential) NumSuffStat

func (Exponential) NumSuffStat() int

NumSuffStat returns the number of sufficient statistics for the distribution.

func (Exponential) Prob

func (e Exponential) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Exponential) Quantile

func (e Exponential) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (Exponential) Rand

func (e Exponential) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Exponential) Score

func (e Exponential) Score(deriv []float64, x float64) []float64

Score returns the score function with respect to the parameters of the distribution at the input location x. The score function is the derivative of the log-likelihood at x with respect to the parameters

(∂/∂θ) log(p(x;θ))

If deriv is non-nil, len(deriv) must equal the number of parameters otherwise Score will panic, and the derivative is stored in-place into deriv. If deriv is nil a new slice will be allocated and returned.

The order is [∂LogProb / ∂Rate].

For more information, see https://en.wikipedia.org/wiki/Score_%28statistics%29.

Special cases:

Score(0) = [NaN]

func (Exponential) ScoreInput

func (e Exponential) ScoreInput(x float64) float64

ScoreInput returns the score function with respect to the input of the distribution at the input location specified by x. The score function is the derivative of the log-likelihood

(d/dx) log(p(x)) .

Special cases:

ScoreInput(0) = NaN

func (Exponential) Skewness

func (Exponential) Skewness() float64

Skewness returns the skewness of the distribution.

func (Exponential) StdDev

func (e Exponential) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Exponential) SuffStat

func (Exponential) SuffStat(samples, weights, suffStat []float64) (nSamples float64)

SuffStat computes the sufficient statistics of set of samples to update the distribution. The sufficient statistics are stored in place, and the effective number of samples are returned.

The exponential distribution has one sufficient statistic, the average rate of the samples.

If weights is nil, the weights are assumed to be 1, otherwise panics if len(samples) != len(weights). Panics if len(suffStat) != NumSuffStat().

func (Exponential) Survival

func (e Exponential) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (Exponential) Variance

func (e Exponential) Variance() float64

Variance returns the variance of the probability distribution.

type F

type F struct {
	D1     float64 // Degrees of freedom for the numerator
	D2     float64 // Degrees of freedom for the denominator
	Source *rand.Rand
}

F implements the F-distribution, a two-parameter continuous distribution with support over the positive real numbers.

The F-distribution has density function

sqrt(((d1*x)^d1) * d2^d2 / ((d1*x+d2)^(d1+d2))) / (x * B(d1/2,d2/2))

where B is the beta function.

For more information, see https://en.wikipedia.org/wiki/F-distribution

func (F) CDF

func (f F) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (F) ExKurtosis

func (f F) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

ExKurtosis returns NaN if the D2 parameter is less or equal to 8.

func (F) LogProb

func (f F) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (F) Mean

func (f F) Mean() float64

Mean returns the mean of the probability distribution.

Mean returns NaN if the D2 parameter is less than or equal to 2.

func (F) Mode

func (f F) Mode() float64

Mode returns the mode of the distribution.

Mode returns NaN if the D1 parameter is less than or equal to 2.

func (F) NumParameters

func (f F) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (F) Prob

func (f F) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (F) Quantile

func (f F) Quantile(p float64) float64

Quantile returns the inverse of the cumulative distribution function.

func (F) Rand

func (f F) Rand() float64

Rand returns a random sample drawn from the distribution.

func (F) Skewness

func (f F) Skewness() float64

Skewness returns the skewness of the distribution.

Skewness returns NaN if the D2 parameter is less than or equal to 6.

func (F) StdDev

func (f F) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

StdDev returns NaN if the D2 parameter is less than or equal to 4.

func (F) Survival

func (f F) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (F) Variance

func (f F) Variance() float64

Variance returns the variance of the probability distribution.

Variance returns NaN if the D2 parameter is less than or equal to 4.

type Gamma

type Gamma struct {
	// Alpha is the shape parameter of the distribution. Alpha must be greater
	// than 0. If Alpha == 1, this is equivalent to an exponential distribution.
	Alpha float64
	// Beta is the rate parameter of the distribution. Beta must be greater than 0.
	// If Beta == 2, this is equivalent to a Chi-Squared distribution.
	Beta float64

	Source *rand.Rand
}

Gamma implements the Gamma distribution, a two-parameter continuous distribution with support over the positive real numbers.

The gamma distribution has density function

β^α / Γ(α) x^(α-1)e^(-βx)

For more information, see https://en.wikipedia.org/wiki/Gamma_distribution

func (Gamma) CDF

func (g Gamma) CDF(x float64) float64

CDF computes the value of the cumulative distribution function at x.

func (Gamma) ExKurtosis

func (g Gamma) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (Gamma) LogProb

func (g Gamma) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Gamma) Mean

func (g Gamma) Mean() float64

Mean returns the mean of the probability distribution.

func (Gamma) Mode

func (g Gamma) Mode() float64

Mode returns the mode of the normal distribution.

The mode is NaN in the special case where the Alpha (shape) parameter is less than 1.

func (Gamma) NumParameters

func (Gamma) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Gamma) Prob

func (g Gamma) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Gamma) Quantile

func (g Gamma) Quantile(p float64) float64

Quantile returns the inverse of the cumulative distribution function.

func (Gamma) Rand

func (g Gamma) Rand() float64

Rand returns a random sample drawn from the distribution.

Rand panics if either alpha or beta is <= 0.

func (Gamma) StdDev

func (g Gamma) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Gamma) Survival

func (g Gamma) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (Gamma) Variance

func (g Gamma) Variance() float64

Variance returns the variance of the probability distribution.

type Laplace

type Laplace struct {
	Mu     float64 // Mean of the Laplace distribution
	Scale  float64 // Scale of the Laplace distribution
	Source *rand.Rand
}

Laplace represents the Laplace distribution (https://en.wikipedia.org/wiki/Laplace_distribution).

func (Laplace) CDF

func (l Laplace) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (Laplace) Entropy

func (l Laplace) Entropy() float64

Entropy returns the entropy of the distribution.

func (Laplace) ExKurtosis

func (l Laplace) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (*Laplace) Fit

func (l *Laplace) Fit(samples, weights []float64)

Fit sets the parameters of the probability distribution from the data samples x with relative weights w. If weights is nil, then all the weights are 1. If weights is not nil, then the len(weights) must equal len(samples).

Note: Laplace distribution has no FitPrior because it has no sufficient statistics.

func (Laplace) LogProb

func (l Laplace) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Laplace) MarshalParameters

func (l Laplace) MarshalParameters(p []Parameter)

MarshalParameters implements the ParameterMarshaler interface

func (Laplace) Mean

func (l Laplace) Mean() float64

Mean returns the mean of the probability distribution.

func (Laplace) Median

func (l Laplace) Median() float64

Median returns the median of the LaPlace distribution.

func (Laplace) Mode

func (l Laplace) Mode() float64

Mode returns the mode of the LaPlace distribution.

func (Laplace) NumParameters

func (l Laplace) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Laplace) Prob

func (l Laplace) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Laplace) Quantile

func (l Laplace) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (Laplace) Rand

func (l Laplace) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Laplace) Score

func (l Laplace) Score(deriv []float64, x float64) []float64

Score returns the score function with respect to the parameters of the distribution at the input location x. The score function is the derivative of the log-likelihood at x with respect to the parameters

(∂/∂θ) log(p(x;θ))

If deriv is non-nil, len(deriv) must equal the number of parameters otherwise Score will panic, and the derivative is stored in-place into deriv. If deriv is nil a new slice will be allocated and returned.

The order is [∂LogProb / ∂Mu, ∂LogProb / ∂Scale].

For more information, see https://en.wikipedia.org/wiki/Score_%28statistics%29.

Special cases:

Score(0) = [0, -0.5/l.Scale]

func (Laplace) ScoreInput

func (l Laplace) ScoreInput(x float64) float64

ScoreInput returns the score function with respect to the input of the distribution at the input location specified by x. The score function is the derivative of the log-likelihood

(d/dx) log(p(x)) .

Special cases:

ScoreInput(l.Mu) = 0

func (Laplace) Skewness

func (Laplace) Skewness() float64

Skewness returns the skewness of the distribution.

func (Laplace) StdDev

func (l Laplace) StdDev() float64

StdDev returns the standard deviation of the distribution.

func (Laplace) Survival

func (l Laplace) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (*Laplace) UnmarshalParameters

func (l *Laplace) UnmarshalParameters(p []Parameter)

UnmarshalParameters implements the ParameterMarshaler interface

func (Laplace) Variance

func (l Laplace) Variance() float64

Variance returns the variance of the probability distribution.

type LogNormal

type LogNormal struct {
	Mu     float64
	Sigma  float64
	Source *rand.Rand
}

LogNormal represents a random variable whose log is normally distributed. The probability density function is given by

1/(x σ √2π) exp(-(ln(x)-μ)^2)/(2σ^2))

func (LogNormal) CDF

func (l LogNormal) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (LogNormal) Entropy

func (l LogNormal) Entropy() float64

Entropy returns the differential entropy of the distribution.

func (LogNormal) ExKurtosis

func (l LogNormal) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (LogNormal) LogProb

func (l LogNormal) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (LogNormal) Mean

func (l LogNormal) Mean() float64

Mean returns the mean of the probability distribution.

func (LogNormal) Median

func (l LogNormal) Median() float64

Median returns the median of the probability distribution.

func (LogNormal) Mode

func (l LogNormal) Mode() float64

Mode returns the mode of the probability distribution.

func (LogNormal) NumParameters

func (LogNormal) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (LogNormal) Prob

func (l LogNormal) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (LogNormal) Quantile

func (l LogNormal) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (LogNormal) Rand

func (l LogNormal) Rand() float64

Rand returns a random sample drawn from the distribution.

func (LogNormal) Skewness

func (l LogNormal) Skewness() float64

Skewness returns the skewness of the distribution.

func (LogNormal) StdDev

func (l LogNormal) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (LogNormal) Survival

func (l LogNormal) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (LogNormal) Variance

func (l LogNormal) Variance() float64

Variance returns the variance of the probability distribution.

type LogProber

type LogProber interface {
	LogProb(float64) float64
}

type Normal

type Normal struct {
	Mu     float64 // Mean of the normal distribution
	Sigma  float64 // Standard deviation of the normal distribution
	Source *rand.Rand
}

Normal respresents a normal (Gaussian) distribution (https://en.wikipedia.org/wiki/Normal_distribution).

Example
package main

import (
	"fmt"

	"github.com/gonum/stat"
	"github.com/gonum/stat/distuv"
)

func main() {
	// Create a normal distribution
	dist := distuv.Normal{
		Mu:    2,
		Sigma: 5,
	}

	data := make([]float64, 1e5)

	// Draw some random values from the standard normal distribution
	for i := range data {
		data[i] = dist.Rand()
	}

	mean, std := stat.MeanStdDev(data, nil)
	meanErr := stat.StdErr(std, float64(len(data)))

	fmt.Printf("mean= %1.1f ± %0.1v\n", mean, meanErr)

}
Output:

mean= 2.0 ± 0.02

func (Normal) CDF

func (n Normal) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (*Normal) ConjugateUpdate

func (n *Normal) ConjugateUpdate(suffStat []float64, nSamples float64, priorStrength []float64)

ConjugateUpdate updates the parameters of the distribution from the sufficient statistics of a set of samples. The sufficient statistics, suffStat, have been observed with nSamples observations. The prior values of the distribution are those currently in the distribution, and have been observed with priorStrength samples.

For the normal distribution, the sufficient statistics are the mean and uncorrected standard deviation of the samples. The prior is having seen strength[0] samples with mean Normal.Mu and strength[1] samples with standard deviation Normal.Sigma. As a result of this function, Normal.Mu and Normal.Sigma are updated based on the weighted samples, and strength is modified to include the new number of samples observed.

This function panics if len(suffStat) != 2 or len(priorStrength) != 2.

func (Normal) Entropy

func (n Normal) Entropy() float64

Entropy returns the differential entropy of the distribution.

func (Normal) ExKurtosis

func (Normal) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (*Normal) Fit

func (n *Normal) Fit(samples, weights []float64)

Fit sets the parameters of the probability distribution from the data samples x with relative weights w. If weights is nil, then all the weights are 1. If weights is not nil, then the len(weights) must equal len(samples).

func (Normal) LogProb

func (n Normal) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Normal) Mean

func (n Normal) Mean() float64

Mean returns the mean of the probability distribution.

func (Normal) Median

func (n Normal) Median() float64

Median returns the median of the normal distribution.

func (Normal) Mode

func (n Normal) Mode() float64

Mode returns the mode of the normal distribution.

func (Normal) NumParameters

func (Normal) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Normal) NumSuffStat

func (Normal) NumSuffStat() int

NumSuffStat returns the number of sufficient statistics for the distribution.

func (Normal) Prob

func (n Normal) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Normal) Quantile

func (n Normal) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (Normal) Rand

func (n Normal) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Normal) Score

func (n Normal) Score(deriv []float64, x float64) []float64

Score returns the score function with respect to the parameters of the distribution at the input location x. The score function is the derivative of the log-likelihood at x with respect to the parameters

(∂/∂θ) log(p(x;θ))

If deriv is non-nil, len(deriv) must equal the number of parameters otherwise Score will panic, and the derivative is stored in-place into deriv. If deriv is nil a new slice will be allocated and returned.

The order is [∂LogProb / ∂Mu, ∂LogProb / ∂Sigma].

For more information, see https://en.wikipedia.org/wiki/Score_%28statistics%29.

func (Normal) ScoreInput

func (n Normal) ScoreInput(x float64) float64

ScoreInput returns the score function with respect to the input of the distribution at the input location specified by x. The score function is the derivative of the log-likelihood

(d/dx) log(p(x)) .

func (Normal) Skewness

func (Normal) Skewness() float64

Skewness returns the skewness of the distribution.

func (Normal) StdDev

func (n Normal) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Normal) SuffStat

func (Normal) SuffStat(samples, weights, suffStat []float64) (nSamples float64)

SuffStat computes the sufficient statistics of a set of samples to update the distribution. The sufficient statistics are stored in place, and the effective number of samples are returned.

The normal distribution has two sufficient statistics, the mean of the samples and the standard deviation of the samples.

If weights is nil, the weights are assumed to be 1, otherwise panics if len(samples) != len(weights). Panics if len(suffStat) != NumSuffStat().

func (Normal) Survival

func (n Normal) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (Normal) Variance

func (n Normal) Variance() float64

Variance returns the variance of the probability distribution.

type Parameter

type Parameter struct {
	Name  string
	Value float64
}

Parameter represents a parameter of a probability distribution

type Quantiler

type Quantiler interface {
	Quantile(p float64) float64
}

type RandLogProber

type RandLogProber interface {
	Rander
	LogProber
}

type Rander

type Rander interface {
	Rand() float64
}

type StudentsT

type StudentsT struct {
	// Mu is the location parameter of the distribution, and the mean of the
	// distribution
	Mu float64

	// Sigma is the scale parameter of the distribution. It is related to the
	// standard deviation by std = Sigma * sqrt(Nu/(Nu-2))
	Sigma float64

	// Nu is the shape prameter of the distribution, representing the number of
	// degrees of the distribution, and one less than the number of observations
	// from a Normal distribution.
	Nu float64

	Src *rand.Rand
}

StudentsT implements the three-parameter Student's T distribution, a distribution over the real numbers.

The Student's T distribution has density function

Γ((ν+1)/2) / (sqrt(νπ) Γ(ν/2) σ) (1 + 1/ν * ((x-μ)/σ)^2)^(-(ν+1)/2)

The Student's T distribution approaches the normal distribution as ν → ∞.

For more information, see https://en.wikipedia.org/wiki/Student%27s_t-distribution, specifically https://en.wikipedia.org/wiki/Student%27s_t-distribution#Non-standardized_Student.27s_t-distribution .

The standard Student's T distribution is with Mu = 0, and Sigma = 1.

func (StudentsT) CDF

func (s StudentsT) CDF(x float64) float64

CDF computes the value of the cumulative distribution function at x.

func (StudentsT) LogProb

func (s StudentsT) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (StudentsT) Mean

func (s StudentsT) Mean() float64

Mean returns the mean of the probability distribution.

func (StudentsT) Mode

func (s StudentsT) Mode() float64

Mode returns the mode of the distribution.

func (StudentsT) NumParameters

func (StudentsT) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (StudentsT) Prob

func (s StudentsT) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (StudentsT) Quantile

func (s StudentsT) Quantile(p float64) float64

Quantile returns the inverse of the cumulative distribution function.

func (StudentsT) Rand

func (s StudentsT) Rand() float64

Rand returns a random sample drawn from the distribution.

func (StudentsT) StdDev

func (s StudentsT) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

The standard deviation is undefined for ν <= 1, and this returns math.NaN().

func (StudentsT) Survival

func (s StudentsT) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (StudentsT) Variance

func (s StudentsT) Variance() float64

Variance returns the variance of the probability distribution.

The variance is undefined for ν <= 1, and this returns math.NaN().

type Uniform

type Uniform struct {
	Min    float64
	Max    float64
	Source *rand.Rand
}

Uniform represents a continuous uniform distribution (https://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29).

func (Uniform) CDF

func (u Uniform) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (Uniform) Entropy

func (u Uniform) Entropy() float64

Entropy returns the entropy of the distribution.

func (Uniform) ExKurtosis

func (Uniform) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (Uniform) LogProb

func (u Uniform) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x.

func (Uniform) MarshalParameters

func (u Uniform) MarshalParameters(p []Parameter)

MarshalParameters implements the ParameterMarshaler interface

func (Uniform) Mean

func (u Uniform) Mean() float64

Mean returns the mean of the probability distribution.

func (Uniform) Median

func (u Uniform) Median() float64

Median returns the median of the probability distribution.

func (Uniform) NumParameters

func (Uniform) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Uniform) Prob

func (u Uniform) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Uniform) Quantile

func (u Uniform) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (Uniform) Rand

func (u Uniform) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Uniform) Skewness

func (Uniform) Skewness() float64

Skewness returns the skewness of the distribution.

func (Uniform) StdDev

func (u Uniform) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Uniform) Survival

func (u Uniform) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (*Uniform) UnmarshalParameters

func (u *Uniform) UnmarshalParameters(p []Parameter)

UnmarshalParameters implements the ParameterMarshaler interface

func (Uniform) Variance

func (u Uniform) Variance() float64

Variance returns the variance of the probability distribution.

type Weibull

type Weibull struct {
	// Shape parameter of the distribution. A value of 1 represents
	// the exponential distribution. A value of 2 represents the
	// Rayleigh distribution. Valid range is (0,+∞).
	K float64
	// Scale parameter of the distribution. Valid range is (0,+∞).
	Lambda float64
	// Source of random numbers
	Source *rand.Rand
}

Weibull distribution. Valid range for x is [0,+∞).

func (Weibull) CDF

func (w Weibull) CDF(x float64) float64

CDF computes the value of the cumulative density function at x.

func (Weibull) Entropy

func (w Weibull) Entropy() float64

Entropy returns the entropy of the distribution.

func (Weibull) ExKurtosis

func (w Weibull) ExKurtosis() float64

ExKurtosis returns the excess kurtosis of the distribution.

func (Weibull) LogCDF

func (w Weibull) LogCDF(x float64) complex128

LogCDF computes the value of the log of the cumulative density function at x.

func (Weibull) LogProb

func (w Weibull) LogProb(x float64) float64

LogProb computes the natural logarithm of the value of the probability density function at x. Zero is returned if x is less than zero.

Special cases occur when x == 0, and the result depends on the shape parameter as follows:

If 0 < K < 1, LogProb returns +Inf.
If K == 1, LogProb returns 0.
If K > 1, LogProb returns -Inf.

func (Weibull) LogSurvival

func (w Weibull) LogSurvival(x float64) float64

Survival returns the log of the survival function (complementary CDF) at x.

func (Weibull) Mean

func (w Weibull) Mean() float64

Mean returns the mean of the probability distribution.

func (Weibull) Median

func (w Weibull) Median() float64

Median returns the median of the normal distribution.

func (Weibull) Mode

func (w Weibull) Mode() float64

Mode returns the mode of the normal distribution.

The mode is NaN in the special case where the K (shape) parameter is less than 1.

func (Weibull) NumParameters

func (Weibull) NumParameters() int

NumParameters returns the number of parameters in the distribution.

func (Weibull) Prob

func (w Weibull) Prob(x float64) float64

Prob computes the value of the probability density function at x.

func (Weibull) Quantile

func (w Weibull) Quantile(p float64) float64

Quantile returns the inverse of the cumulative probability distribution.

func (Weibull) Rand

func (w Weibull) Rand() float64

Rand returns a random sample drawn from the distribution.

func (Weibull) Score

func (w Weibull) Score(deriv []float64, x float64) []float64

Score returns the score function with respect to the parameters of the distribution at the input location x. The score function is the derivative of the log-likelihood at x with respect to the parameters

(∂/∂θ) log(p(x;θ))

If deriv is non-nil, len(deriv) must equal the number of parameters otherwise Score will panic, and the derivative is stored in-place into deriv. If deriv is nil a new slice will be allocated and returned.

The order is [∂LogProb / ∂K, ∂LogProb / ∂λ].

For more information, see https://en.wikipedia.org/wiki/Score_%28statistics%29.

Special cases:

Score(0) = [NaN, NaN]

func (Weibull) ScoreInput

func (w Weibull) ScoreInput(x float64) float64

ScoreInput returns the score function with respect to the input of the distribution at the input location specified by x. The score function is the derivative of the log-likelihood

(d/dx) log(p(x)) .

Special cases:

ScoreInput(0) = NaN

func (Weibull) Skewness

func (w Weibull) Skewness() float64

Skewness returns the skewness of the distribution.

func (Weibull) StdDev

func (w Weibull) StdDev() float64

StdDev returns the standard deviation of the probability distribution.

func (Weibull) Survival

func (w Weibull) Survival(x float64) float64

Survival returns the survival function (complementary CDF) at x.

func (Weibull) Variance

func (w Weibull) Variance() float64

Variance returns the variance of the probability distribution.

Jump to

Keyboard shortcuts

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