alg

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package alg stores useful algorithms and math functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChooseX

func ChooseX(weights []float64, n int) []int

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

func CumWeightedChooseOne(remainingWeights []float64) int

CumWeightedChooseOne returns a single index from the weights given at a rate relative to the magnitude of each weight

func CumWeightedFromMap

func CumWeightedFromMap(weightMap map[int]float64) int

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 F64eq added in v1.1.0

func F64eq(f1, f2 float64) bool

F64eq uses epsilon equality to compare two float64s

func RoundF64

func RoundF64(a float64) int

RoundF64 rounds a float to an int

func UniqueChooseX

func UniqueChooseX(weights []float64, n int) []int

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

func WeightedChoose(weights []float64, toChoose int) ([]int, error)

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.

Directories

Path Synopsis
Package intgeom stores primitives for integer geometry
Package intgeom stores primitives for integer geometry

Jump to

Keyboard shortcuts

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