probability

package
v0.0.0-...-903af30 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bayes

func Bayes(probA, probBgivenA, probB float64) (float64, error)

Bayes is a trivial implemention of Bayes' rule. We assume probB is already the sum of all the posteriors for B (its prior) for all possible values of A. NEEDS TESTS

func MassGeometric

func MassGeometric(p float64) (func(int) float64, error)

MassGeometric returns a probability mass function (PMF) which computes the probability that a given event will occur for the first time after (x-1) nonoccurrences - so the event occurs on the xth opportunity. p is the probabiliity of the event occurring, 1-p is its complement, and the full function is given by (1-p)^(x-1) * p. NEEDS TESTS

Types

type DiscretizationConfig

type DiscretizationConfig struct {
	Intervals         int
	Method            DiscretizationMethod
	IncludeUpperBound bool // Unused for now
}

DiscretizationConfig controls the behavior of discretization of a continuous range of values. Intervals is the number of intervals, Method determines how the range is subdivided, and IncludeUpperBound toggles whether each interval includes its upper bound (default of false means that only the last interval includes its upper bound, all others exclude it).

type DiscretizationMethod

type DiscretizationMethod int
const (
	IntervalEqualSize         DiscretizationMethod = iota // Every interval is the same size
	IntervalEqualDistribution DiscretizationMethod = iota // Every interval contains the same number of known values
	DefaultIntervalCount                           = 10
)

type Interval

type Interval struct {
	Lower         float64
	Upper         float64
	Size          float64
	IncludesLower bool
	IncludesUpper bool
}

func Discretize

func Discretize(vals []float64, cfg DiscretizationConfig) []Interval

Discretize converts a continuous (real-valued) range into a set of discrete intervals. vals is the set of known values within the range. Pass an empty config object to get the default behavior of 10 intervals, each interval is of equal size, every interval but the last includes its lower bound and excludes its upper bound. The last interval includes both bounds by default.

func (*Interval) Contains

func (i *Interval) Contains(val float64) bool

Contains returns true of the specified value is contained by the interval, false otherwise

type Intervals

type Intervals []Interval

func (Intervals) IntervalForValue

func (is Intervals) IntervalForValue(val float64) int

IntervalForValue returns the index 0..(len(is) - 1) of the Interval containing the passed value

type ProbabilityMassFunction

type ProbabilityMassFunction func(int) float64

func MassDiscrete

func MassDiscrete(values []int) ProbabilityMassFunction

MassDiscrete returns a probability mass function (PMF) over the range of values which can be assigned to a given random variable. The variable has a discrete range, and the values must represent the full sample space.

Jump to

Keyboard shortcuts

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