alg

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package alg stores useful algorithms and math functions

Index

Constants

View Source
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

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

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

func CumulativeWeights(weights []float64) []float64

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

func F64eq(f1, f2 float64) bool

F64eq equates two float64s within a small epsilon.

func F64eqEps

func F64eqEps(f1, f2, epsilon float64) bool

F64eqEps equates two float64s within a provided epsilon.

func RemainingWeights

func RemainingWeights(weights []float64) []float64

RemainingWeights is equivalent to CumulativeWeights with the slice reversed, where the zeroth element will contain the total weight.

func RoundF64

func RoundF64(a float64) int

RoundF64 rounds a float64 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 WeightedChooseOne

func WeightedChooseOne(remainingWeights []float64) int

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

func WeightedMapChoice(weightMap map[int]float64) int

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.

Types

type Degree

type Degree float64

A Degree value is a float that specifies it should be in degrees.

func (Degree) Radians

func (d Degree) Radians() Radian

Radians converts a Degree to Radians.

type Radian

type Radian float64

A Radian value is a float that specifies it should be in radians.

func (Radian) Degrees

func (r Radian) Degrees() Degree

Degrees converts a Radian to Degrees.

Directories

Path Synopsis
Package floatgeom stores primitives for floating point geometry
Package floatgeom stores primitives for floating point geometry
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