Documentation ¶
Index ¶
- Variables
- func Max(x []float64) float64
- func MaxLt(x []float64, val float64) float64
- func Mean(x []float64) float64
- func Min(x []float64) float64
- func MinGt(x []float64, val float64) float64
- func Sum(x []float64) float64
- func Variance(x []float64) float64
- type BernoulliDist
- func (dist *BernoulliDist) BSpace() booleanSpace
- func (dist BernoulliDist) CDF(val float64) float64
- func (dist BernoulliDist) Mean() float64
- func (dist BernoulliDist) Mode() float64
- func (dist BernoulliDist) NumParams() int
- func (dist BernoulliDist) Score(vars, params []float64) float64
- func (dist *BernoulliDist) SetBias(bias float64)
- func (dist *BernoulliDist) SetParams(vals []float64)
- func (dist BernoulliDist) Variance() float64
- type Beta
- func (dist Beta) CDF(val float64) float64
- func (dist Beta) MaximizeByMoM(vals []float64) *Beta
- func (dist Beta) Mean() float64
- func (dist Beta) Mode() float64
- func (dist Beta) NumParams() int
- func (dist Beta) NumVars() int
- func (dist Beta) PDF(val float64) float64
- func (dist Beta) Posterior(pos, neg float64) *Beta
- func (dist Beta) Sample() float64
- func (dist Beta) Score(vars, params []float64) float64
- func (dist *Beta) SetParams(vals []float64)
- func (dist Beta) Space() RealSpace
- func (dist Beta) Variance() float64
- type ContinuousDist
- type DefContinuousDistLgProb
- type DefContinuousDistProb
- type DefContinuousDistSampleN
- type DefDiscreteDistLgProb
- type DefDiscreteDistSample
- type DefDiscreteDistSampleN
- type DenseMutableDiscreteDist
- func (dist *DenseMutableDiscreteDist) Normalize()
- func (dist *DenseMutableDiscreteDist) NormalizeWithExtra(rest float64)
- func (dist DenseMutableDiscreteDist) NumParams() int
- func (dist DenseMutableDiscreteDist) NumVars() int
- func (dist DenseMutableDiscreteDist) Prob(outcome Outcome) float64
- func (dist *DenseMutableDiscreteDist) Reset()
- func (dist DenseMutableDiscreteDist) Score(vars, params []float64) float64
- func (dist *DenseMutableDiscreteDist) SetParams(vals []float64)
- func (dist *DenseMutableDiscreteDist) SetProb(outcome Outcome, prob float64)
- func (dist *DenseMutableDiscreteDist) SetWeight(outcome Outcome, weight float64)
- func (dist DenseMutableDiscreteDist) Space() DiscreteSpace
- type DiscreteDist
- type DiscreteObjectSpace
- type DiscreteRealDist
- type DiscreteRealSpace
- type DiscreteSpace
- type Dist
- type MutableDiscreteDist
- type Normal
- func (dist Normal) CDF(val float64) float64
- func (dist Normal) Mean() float64
- func (dist Normal) Mode() float64
- func (dist Normal) NumParams() int
- func (dist Normal) NumVars() int
- func (dist Normal) PDF(val float64) float64
- func (dist Normal) Sample() float64
- func (dist Normal) Score(vars, params []float64) float64
- func (dist *Normal) SetParams(vals []float64)
- func (dist Normal) Space() RealSpace
- func (dist Normal) Variance() float64
- type Outcome
- type RealDist
- type RealIntervalSpace
- type RealLikeSpace
- type RealSpace
- type Space
Constants ¶
This section is empty.
Variables ¶
var AllRealSpace = RealIntervalSpace{Min: math.Inf(-1), Max: math.Inf(+1)}
The space of all reals
var BooleanSpace booleanSpace
The canonical instance of booleanSpace
var PositiveRealSpace positiveRealSpace
The canonical instance of positiveRealSpace
var UnitIntervalSpace = RealIntervalSpace{Min: 0, Max: 1}
The canonical unit interval space
Functions ¶
func MaxLt ¶
Find the largest value strictly less than the provided value. If there is no such value, then val is returned.
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 (Beta) MaximizeByMoM ¶
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) Posterior ¶
Return the Bayesian posterior using this Beta as a prior distribution, and having observed `pos` positive and `neg` negative outcomes.
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 ¶
func (dist DenseMutableDiscreteDist) Space() DiscreteSpace
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 ¶
Produce a new Normal distribution
func NewStandardNormalDist ¶
func NewStandardNormalDist() *Normal
Produce a new standard Normal distribution
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