Documentation ¶
Overview ¶
Package alg stores useful algorithms and math functions
Index ¶
- Constants
- func ChooseX(weights []float64, n int) []int
- func CumulativeWeights(weights []float64) []float64
- func F64eq(f1, f2 float64) bool
- func F64eqEps(f1, f2, epsilon float64) bool
- func RemainingWeights(weights []float64) []float64
- func RoundF64(a float64) int
- func UniqueChooseX(weights []float64, n int) []int
- func WeightedChooseOne(remainingWeights []float64) int
- func WeightedMapChoice(weightMap map[int]float64) int
- type Degree
- type Radian
Constants ¶
const ( // DegToRad is the constant value something in // degrees should be multiplied by to obtain // something in radians. DegToRad = math.Pi / 180 // RadToDeg is the constant value something in // radians should be multiplied by to obtain // something in degrees. RadToDeg = 180 / math.Pi )
Variables ¶
This section is empty.
Functions ¶
func ChooseX ¶
ChooseX - also known as 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 CumulativeWeights ¶ added in v1.5.0
CumulativeWeights converts a slice of weights into a slice of cumulative weights, where each index is the sum of all weights up until that index in the original slice
func RemainingWeights ¶
RemainingWeights is equivalent to CumulativeWeights with the slice reversed, where the zeroth element will contain the total weight.
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 WeightedChooseOne ¶
WeightedChooseOne returns a single index from the weights given at a rate relative to the magnitude of each weight. It expects the input to be in the form of RemainingWeights, cumulative with the total at index 0.
func WeightedMapChoice ¶
WeightedMapChoice converts the input map into a set where keys are indices and values are weights for WeightedChooseOne, then returns the key for WeightedChooseOne of the weights.