Documentation ¶
Overview ¶
Package alg stores useful algorithms and math functions
Index ¶
- func ChooseX(weights []float64, n int) []int
- func CumWeightedChooseOne(remainingWeights []float64) int
- func CumWeightedFromMap(weightMap map[int]float64) int
- func F64eq(f1, f2 float64) bool
- func RoundF64(a float64) int
- func UniqueChooseX(weights []float64, n int) []int
- func WeightedChoose(weights []float64, toChoose int) ([]int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChooseX ¶
ChooseX AKA Roulette search
This returns n indices from the input weights at a count relative to the weight of each index. It can return the same index multiple times.
func CumWeightedChooseOne ¶
CumWeightedChooseOne returns a single index from the weights given at a rate relative to the magnitude of each weight
func CumWeightedFromMap ¶
CumWeightedFromMap converts the input map into a set where keys are indices and values are weights for CumWeightedChooseOne, then returns the key for CumWeightedChooseOne of the weights.
func UniqueChooseX ¶
UniqueChooseX returns n indices from the input weights at a count relative to the weight of each index. This will never return duplicate indices. if n > len(weights), it will return -1 after depleting the n elements from weights.
func WeightedChoose ¶
WeightedChoose will return toChoose indices from weights. the output can have duplicate indices, and zero-weights will cause this algorithm to malfunction. Deprecated: Use ChooseX or UniqueChooseX instead, as they'll perform more reliably and give better distributions.
Types ¶
This section is empty.