mathutil

package
v1.20240719.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package mathutil provides the missing standard library math functions we need for various statistical computations.

Index

Constants

View Source
const (

	// Epsilon represents the minimum amount of relevant delta we care about.
	Epsilon = 0.00000001
)

Variables

This section is empty.

Functions

func AbsDuration added in v1.20210402.3

func AbsDuration(d time.Duration) time.Duration

AbsDuration returns the absolute value of a duration.

func Copy

func Copy(input []float64) []float64

Copy copies an array of float64s.

func CopyDurations

func CopyDurations(input []time.Duration) []time.Duration

CopyDurations copies an array of time.Duration.

func CopyInts

func CopyInts(input []int) []int

CopyInts copies an array of float64s.

func CopySort

func CopySort(input []float64) []float64

CopySort copies and sorts an array of floats.

func CopySortDurations

func CopySortDurations(input []time.Duration) []time.Duration

CopySortDurations copies and sorts an array of floats.

func CopySortInts

func CopySortInts(input []int) []int

CopySortInts copies and sorts an array of floats.

func DegreesAdd

func DegreesAdd(baseDegrees, deltaDegrees float64) float64

DegreesAdd adds a delta to a base in radians.

func DegreesToCompass

func DegreesToCompass(deg float64) float64

DegreesToCompass returns the degree value in compass / clock orientation.

func DegreesToRadians

func DegreesToRadians(degrees float64) float64

DegreesToRadians returns degrees as radians.

func InEpsilon

func InEpsilon(a, b float64) bool

InEpsilon returns if two values are within the Epsilon of each other absolutely.

func Max

func Max(input []float64) float64

Max finds the highest value in a slice.

func MaxInts

func MaxInts(input []int) int

MaxInts finds the highest value in a slice.

func Mean

func Mean(input []float64) float64

Mean gets the average of a slice of numbers

func MeanDurations

func MeanDurations(input []time.Duration) time.Duration

MeanDurations gets the average of a slice of numbers

func MeanInts

func MeanInts(input []int) float64

MeanInts gets the average of a slice of numbers

func Median

func Median(input []float64) (median float64)

Median gets the median number in a slice of numbers

func MedianSorted

func MedianSorted(sortedInput []float64) (median float64)

MedianSorted gets the median number in a sorted slice of numbers

func Min

func Min(input []float64) float64

Min finds the lowest value in a slice.

func MinInts

func MinInts(input []int) int

MinInts finds the lowest value in a slice.

func MinMax

func MinMax(values []float64) (min, max float64)

MinMax returns both the min and max in one pass.

func MinMaxDurations

func MinMaxDurations(values []time.Duration) (min, max time.Duration)

MinMaxDurations returns both the min and max of time.Duration in one pass.

func MinMaxInts

func MinMaxInts(values []int) (min, max int)

MinMaxInts returns both the min and max of ints in one pass.

func Mode

func Mode(input []float64) []float64

Mode gets the mode of a slice of numbers `Mode` generally is the most frequently occurring values within the input set.

func Normalize

func Normalize(values ...float64) []float64

Normalize returns a set of numbers on the interval [0,1] for a given set of inputs. An example: 4,3,2,1 => 0.4, 0.3, 0.2, 0.1 Caveat; the total may be < 1.0; there are going to be issues with irrational numbers etc.

func PercentDifference

func PercentDifference(v1, v2 float64) float64

PercentDifference computes the percentage difference between two values. The formula is (v2-v1)/v1.

func PercentToRadians

func PercentToRadians(pct float64) float64

PercentToRadians converts a normalized value (0,1) to radians.

func Percentile

func Percentile(input []float64, percent float64) float64

Percentile finds the relative standing in a slice of floats. `percent` should be given on the interval [0,100.0).

func PercentileOfDuration

func PercentileOfDuration(input []time.Duration, percentile float64) time.Duration

PercentileOfDuration finds the relative standing in a slice of durations

func PercentileSorted

func PercentileSorted(sortedInput []float64, percent float64) float64

PercentileSorted finds the relative standing in a sorted slice of floats. `percent` should be given on the interval [0,100.0).

func PercentileSortedDurations

func PercentileSortedDurations(sortedInput []time.Duration, percentile float64) time.Duration

PercentileSortedDurations finds the relative standing in a sorted slice of durations

func PowInt

func PowInt(base int, power uint) int

PowInt returns the base to the power.

func RadianAdd

func RadianAdd(base, delta float64) float64

RadianAdd adds a delta to a base in radians.

func RadiansToDegrees

func RadiansToDegrees(value float64) float64

RadiansToDegrees translates a radian value to a degree value.

func RoundDown

func RoundDown(value, roundTo float64) float64

RoundDown rounds down to a given roundTo value.

func RoundPlaces

func RoundPlaces(input float64, places int) float64

RoundPlaces a float to a specific decimal place or precision

func RoundUp

func RoundUp(value, roundTo float64) float64

RoundUp rounds up to a given roundTo value.

func StdDevP

func StdDevP(input []float64) float64

StdDevP finds the amount of variation from the population

func StdDevS

func StdDevS(input []float64) float64

StdDevS finds the amount of variation from a sample

func Sum

func Sum(input []float64) float64

Sum adds all the numbers of a slice together

func SumDurations

func SumDurations(values []time.Duration) time.Duration

SumDurations adds all the numbers of a slice together

func SumInts

func SumInts(values []int) int

SumInts adds all the numbers of a slice together

func Var

func Var(input []float64, sample int) (variance float64)

Var finds the variance for both population and sample data

func VarP

func VarP(input []float64) float64

VarP finds the amount of variance within a population

func VarS

func VarS(input []float64) float64

VarS finds the amount of variance within a sample

Types

type Durations

type Durations []time.Duration

Durations is an array of durations.

func (Durations) Len

func (d Durations) Len() int

Len implements sort.Sorter

func (Durations) Less

func (d Durations) Less(i, j int) bool

Less implements sort.Sorter

func (Durations) Swap

func (d Durations) Swap(i, j int)

Swap implements sort.Sorter

Jump to

Keyboard shortcuts

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