dist

package
v0.0.0-...-d568a9c Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllRealSpace = RealIntervalSpace{Min: math.Inf(-1), Max: math.Inf(+1)}

The space of all reals

View Source
var BooleanSpace booleanSpace

The canonical instance of booleanSpace

View Source
var PositiveRealSpace positiveRealSpace

The canonical instance of positiveRealSpace

View Source
var UnitIntervalSpace = RealIntervalSpace{Min: 0, Max: 1}

The canonical unit interval space

Functions

func Max

func Max(x []float64) float64

Find the maximum of an array of values

func MaxLt

func MaxLt(x []float64, val float64) float64

Find the largest value strictly less than the provided value. If there is no such value, then val is returned.

func Mean

func Mean(x []float64) float64

Compute the sample mean of an array of values

func Min

func Min(x []float64) float64

Find the minimum of an array of values

func MinGt

func MinGt(x []float64, val float64) float64

Find the smallest value strictly greater than the provided value. If there is no such value, then val is returned.

func Sum

func Sum(x []float64) float64

Compute the sum of an array of values

func Variance

func Variance(x []float64) float64

Compute the sample variance of an array of values

Types

type BernoulliDist

type BernoulliDist struct {
	*DenseMutableDiscreteDist
}

A Bernoulli distribution. See: https://en.wikipedia.org/wiki/Bernoulli_distribution

func NewBernoulliDist

func NewBernoulliDist(bias float64) *BernoulliDist

Create a new Bernoulli distribution

func (*BernoulliDist) BSpace

func (dist *BernoulliDist) BSpace() booleanSpace

Return the space as a BooleanSpace

func (BernoulliDist) CDF

func (dist BernoulliDist) CDF(val float64) float64

The value of the CDF: Pr(X <= val) for random variable X over this space

func (BernoulliDist) Mean

func (dist BernoulliDist) Mean() float64

The mean, or expected value, of the random variable

func (BernoulliDist) Mode

func (dist BernoulliDist) Mode() float64

The mode of the random variable

func (BernoulliDist) NumParams

func (dist BernoulliDist) NumParams() int

The number of parameters in the distribution: the weights

func (BernoulliDist) Score

func (dist BernoulliDist) Score(vars, params []float64) float64

Return a "score" (log density or log mass) for the given values

func (*BernoulliDist) SetBias

func (dist *BernoulliDist) SetBias(bias float64)

Set the bias of the distribution

func (*BernoulliDist) SetParams

func (dist *BernoulliDist) SetParams(vals []float64)

Update the distribution parameters

func (BernoulliDist) Variance

func (dist BernoulliDist) Variance() float64

The variance of the random variable

type Beta

type Beta struct {

	// The distribution parameters
	Alpha, Beta float64

	DefContinuousDistSampleN
	DefContinuousDistProb
	DefContinuousDistLgProb
	// contains filtered or unexported fields
}

A Beta distribution. See: https://en.wikipedia.org/wiki/Beta_distribution

func NewBetaDist

func NewBetaDist(alpha, beta float64) *Beta

Produce a new Beta distribution

func (Beta) CDF

func (dist Beta) CDF(val float64) float64

The value of the CDF: Pr(X <= val) for random variable X over this space

func (Beta) MaximizeByMoM

func (dist Beta) MaximizeByMoM(vals []float64) *Beta

Return the Beta which maximizes the probability of emitting the given sequence, based on a method of moments estimation. See: http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm

func (Beta) Mean

func (dist Beta) Mean() float64

The mean, or expected value, of the random variable

func (Beta) Mode

func (dist Beta) Mode() float64

The mode of the random variable

func (Beta) NumParams

func (dist Beta) NumParams() int

The number of parameters in the distribution

func (Beta) NumVars

func (dist Beta) NumVars() int

The number of random variables the distribution is over

func (Beta) PDF

func (dist Beta) PDF(val float64) float64

Return the density at a given value

func (Beta) Posterior

func (dist Beta) Posterior(pos, neg float64) *Beta

Return the Bayesian posterior using this Beta as a prior distribution, and having observed `pos` positive and `neg` negative outcomes.

func (Beta) Sample

func (dist Beta) Sample() float64

Sample an outcome from the distribution

func (Beta) Score

func (dist Beta) Score(vars, params []float64) float64

Return a "score" (density or probability) for the given values

func (*Beta) SetParams

func (dist *Beta) SetParams(vals []float64)

Update the distribution parameters

func (Beta) Space

func (dist Beta) Space() RealSpace

Return the corresponding sample space

func (Beta) Variance

func (dist Beta) Variance() float64

The variance of the random variable

type ContinuousDist

type ContinuousDist interface {
	Dist
	RealDist

	// Sample an outcome from the distribution
	Sample() float64

	// Sample a sequence of n outcomes from the distribution
	SampleN(n int) []float64

	// Return the corresponding sample space
	Space() RealSpace

	// The value of the CDF: Pr(X <= val) for random variable X over this space
	CDF(val float64) float64

	// Return the density at a given value
	PDF(val float64) float64

	// Return the probability of a given interval
	Prob(from, to float64) float64

	// Return the log probability (base 2) of a given interval
	LgProb(from, to float64) float64
}

Represents a continuous distribution over a subset of reals

type DefContinuousDistLgProb

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

A default implementation of LgProb() for a ContinuousDist

func (DefContinuousDistLgProb) LgProb

func (dist DefContinuousDistLgProb) LgProb(from, to float64) float64

Return the log probability (base 2) of a given outcome

type DefContinuousDistProb

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

A default implementation of Prob() for a ContinuousDist

func (DefContinuousDistProb) Prob

func (dist DefContinuousDistProb) Prob(from, to float64) float64

Return the log probability (base 2) of a given outcome

type DefContinuousDistSampleN

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

A default implementation of SampleN() for a ContinuousDist

func (DefContinuousDistSampleN) SampleN

func (dist DefContinuousDistSampleN) SampleN(n int) []float64

type DefDiscreteDistLgProb

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

A default implementation of LgProb() for a DiscreteDist

func (DefDiscreteDistLgProb) LgProb

func (dist DefDiscreteDistLgProb) LgProb(outcome Outcome) float64

Return the log probability (base 2) of a given outcome

type DefDiscreteDistSample

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

A default implementation of Sample() for a DiscreteDist

func (DefDiscreteDistSample) Sample

func (dist DefDiscreteDistSample) Sample() Outcome

type DefDiscreteDistSampleN

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

A default implementation of SampleN() for a DiscreteDist

func (DefDiscreteDistSampleN) SampleN

func (dist DefDiscreteDistSampleN) SampleN(n int) []Outcome

type DenseMutableDiscreteDist

type DenseMutableDiscreteDist struct {
	DefDiscreteDistSample
	DefDiscreteDistSampleN
	DefDiscreteDistLgProb
	// contains filtered or unexported fields
}

A mutable discrete distribution which stores a dense probability vector for its outcomes.

func NewDenseMutableDiscreteDist

func NewDenseMutableDiscreteDist(space DiscreteSpace) *DenseMutableDiscreteDist

Make a new instance of DenseMutableDiscreteDist

func (*DenseMutableDiscreteDist) Normalize

func (dist *DenseMutableDiscreteDist) Normalize()

Normalize all weights, assuming 0 weight for outcomes not assigned with SetWeight() since the last call to Normalize().

func (*DenseMutableDiscreteDist) NormalizeWithExtra

func (dist *DenseMutableDiscreteDist) NormalizeWithExtra(rest float64)

Normalize all weights, assigning `rest` weight uniformly to all outcomes currently assigned zero weight.

func (DenseMutableDiscreteDist) NumParams

func (dist DenseMutableDiscreteDist) NumParams() int

The number of parameters in the distribution: the weights

func (DenseMutableDiscreteDist) NumVars

func (dist DenseMutableDiscreteDist) NumVars() int

The number of random variables the distribution is over

func (DenseMutableDiscreteDist) Prob

func (dist DenseMutableDiscreteDist) Prob(outcome Outcome) float64

Return the probability of a given outcome

func (*DenseMutableDiscreteDist) Reset

func (dist *DenseMutableDiscreteDist) Reset()

Set all probabilities to zero

func (DenseMutableDiscreteDist) Score

func (dist DenseMutableDiscreteDist) Score(vars, params []float64) float64

Return a "score" (density or probability) for the given values

func (*DenseMutableDiscreteDist) SetParams

func (dist *DenseMutableDiscreteDist) SetParams(vals []float64)

Update the distribution parameters

func (*DenseMutableDiscreteDist) SetProb

func (dist *DenseMutableDiscreteDist) SetProb(outcome Outcome, prob float64)

Set the probability of a particular outcome

func (*DenseMutableDiscreteDist) SetWeight

func (dist *DenseMutableDiscreteDist) SetWeight(outcome Outcome, weight float64)

Set the unnormalized measure for a particular outcome. It is up to the particular distribution to normalize these weights.

func (DenseMutableDiscreteDist) Space

Return the sample space

type DiscreteDist

type DiscreteDist interface {
	Dist

	// Sample an outcome from the distribution
	Sample() Outcome

	// Sample a sequence of n outcomes from the distribution
	SampleN(n int) []Outcome

	// Return the corresponding sample space
	Space() DiscreteSpace

	// Return the probability of a given outcome
	Prob(outcome Outcome) float64

	// Return the log probability (base 2) of a given outcome
	LgProb(outcome Outcome) float64
}

Represents a discrete distribution over a sample space

type DiscreteObjectSpace

type DiscreteObjectSpace struct {

	// The objects which the space is over
	Objects []interface{}
}

A discrete space over arbitrary objects

func (DiscreteObjectSpace) Equals

func (sp DiscreteObjectSpace) Equals(other Space) bool

Ask whether the space is the same as some other space

func (DiscreteObjectSpace) Outcome

func (sp DiscreteObjectSpace) Outcome(val interface{}) Outcome

func (DiscreteObjectSpace) Size

func (sp DiscreteObjectSpace) Size() int

Returns the number of outcomes in the space if finite, and returns -1 if infinite.

func (DiscreteObjectSpace) Value

func (sp DiscreteObjectSpace) Value(outcome Outcome) interface{}

type DiscreteRealDist

type DiscreteRealDist interface {
	DiscreteDist
	RealDist
}

A discrete distribution over the reals

type DiscreteRealSpace

type DiscreteRealSpace interface {
	DiscreteSpace
	RealLikeSpace

	// The real value of an outcome
	F64Value(outcome Outcome) float64

	// The outcome corresponding to a real value
	Outcome(value float64) Outcome
}

A discrete subset of the reals

type DiscreteSpace

type DiscreteSpace interface {

	// Every discrete space is a space
	Space

	// Returns the number of outcomes in the space if finite, and
	// returns -1 if infinite.
	Size() int
}

A sample space over a discrete set

type Dist

type Dist interface {

	// Return a "score" (density or probability) for the given values
	Score(vars, params []float64) float64

	// The number of random variables the distribution is over
	NumVars() int

	// The number of parameters in the distribution
	NumParams() int

	// Update the distribution parameters
	SetParams(vals []float64)
}

Represents a probability distribution

type MutableDiscreteDist

type MutableDiscreteDist interface {

	// A mutable dist is a dist
	DiscreteDist

	// Set all probabilities to zero
	Reset()

	// Set the probability of a particular outcome
	SetProb(outcome Outcome, prob float64)

	// Set the unnormalized measure for a particular outcome. It is
	// up to the particular distribution to normalize these weights.
	SetWeight(outcome Outcome, weight float64)

	// Normalize all weights, assuming 0 weight for outcomes not assigned with
	// SetWeight() since the last call to Normalize().
	Normalize()

	// Normalize all weights, assigning `rest` weight uniformly to all outcomes
	// currently assigned zero weight.
	NormalizeWithExtra(rest float64)
}

A discrete distribution whose underlying probability measure can change

type Normal

type Normal struct {

	// The distribution parameters
	Mu, Sigma float64

	DefContinuousDistSampleN
	DefContinuousDistProb
	DefContinuousDistLgProb
	// contains filtered or unexported fields
}

A Normal distribution. See: https://en.wikipedia.org/wiki/Normal_distribution

func NewNormalDist

func NewNormalDist(mean, stdDev float64) *Normal

Produce a new Normal distribution

func NewStandardNormalDist

func NewStandardNormalDist() *Normal

Produce a new standard Normal distribution

func (Normal) CDF

func (dist Normal) CDF(val float64) float64

The value of the CDF: Pr(X <= val) for random variable X over this space

func (Normal) Mean

func (dist Normal) Mean() float64

The mean, or expected value, of the random variable

func (Normal) Mode

func (dist Normal) Mode() float64

The mode of the random variable

func (Normal) NumParams

func (dist Normal) NumParams() int

The number of parameters in the distribution

func (Normal) NumVars

func (dist Normal) NumVars() int

The number of random variables the distribution is over

func (Normal) PDF

func (dist Normal) PDF(val float64) float64

Return the density at a given value

func (Normal) Sample

func (dist Normal) Sample() float64

Sample an outcome from the distribution

func (Normal) Score

func (dist Normal) Score(vars, params []float64) float64

Return a "score" (density or probability) for the given values

func (*Normal) SetParams

func (dist *Normal) SetParams(vals []float64)

Update the distribution parameters

func (Normal) Space

func (dist Normal) Space() RealSpace

Return the corresponding sample space

func (Normal) Variance

func (dist Normal) Variance() float64

The variance of the random variable

type Outcome

type Outcome int

An ID for a particular outcome in a space

type RealDist

type RealDist interface {

	// The mean, or expected value, of the random variable
	Mean() float64

	// The mode of the random variable
	Mode() float64

	// The variance of the random variable
	Variance() float64
}

Represents a distribution over reals for a random variable

type RealIntervalSpace

type RealIntervalSpace struct {
	Min, Max float64
}

A subset of the reals on a continuous closed interval

func NewRealIntervalSpace

func NewRealIntervalSpace(min, max float64) *RealIntervalSpace

Create a new RealIntervalSpace with the specified bounds

func (RealIntervalSpace) Equals

func (sp RealIntervalSpace) Equals(other Space) bool

Ask whether the space is the same as some other space

func (RealIntervalSpace) Inf

func (space RealIntervalSpace) Inf() float64

The infimum (min) value in the space, or negative infinity

func (RealIntervalSpace) Sup

func (space RealIntervalSpace) Sup() float64

The supremum (max) value in the space, or positive infinity

type RealLikeSpace

type RealLikeSpace interface {

	// The infimum (min) value in the space, or negative infinity
	Inf() float64

	// The supremum (max) value in the space, or positive infinity
	Sup() float64
}

Methods contained by spaces over real values

type RealSpace

type RealSpace interface {
	Space
	RealLikeSpace
}

A subset of the reals

type Space

type Space interface {

	// Ask whether the space is the same as some other space
	Equals(other Space) bool
}

A set of outcomes for some probability measure.

Jump to

Keyboard shortcuts

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