alg

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 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, x int) []int

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

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 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.

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.

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