Documentation ¶
Index ¶
- func ChooseX(weights []float64, x int) []int
- func CumWeightedChooseOne(remainingWeights []float64) int
- func CumWeightedFromMap(weightMap map[int]float64) int
- 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 algorithm works well, the only issue relative to above is that it can choose the same element multiple times, which is not always the desired effect.
A version of it could easily be made to only pick each element once, however. It would benefit from the linear pseudo-random roulette search, where forced increments would happen once an index was chosen.
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 uses a heap structure to poll a set of weights n times. This will never return duplicate weights and due to the heap structure is efficient.
Types ¶
This section is empty.