Project: KEDA (Orchestration & Management / Scheduling & Orchestration)
File: DOCUMENTATION.md

`import "github.com/montanaflynn/stats"` Package stats is a well tested and comprehensive statistics library package with no dependencies. Example Usage: // start with some source data to use data := []float64{1.0, 2.1, 3.2, 4.823, 4.1, 5.8} // you could also use different types like this // data := stats.LoadRawData([]int{1, 2, 3, 4, 5}) // data := stats.LoadRawData([]interface{}{1.1, "2", 3}) // etc... median, _ := stats.Median(data) fmt.Println(median) // 3.65 roundedMedian, _ := stats.Round(median, 0) fmt.Println(roundedMedian) // 4 MIT License Copyright (c) 2014-2020 Montana Flynn (<a href="https://montanaflynn.com">https://montanaflynn.com</a>) * * * * * * * * * * * * * * * * * * * * * * * * * * ``` go var ( // ErrEmptyInput Input must not be empty ErrEmptyInput = statsError{"Input must not be empty."} // ErrNaN Not a number ErrNaN = statsError{"Not a number."} // ErrNegative Must not contain negative values ErrNegative = statsError{"Must not contain negative values."} // ErrZero Must not contain zero values ErrZero = statsError{"Must not contain zero values."} // ErrBounds Input is outside of range ErrBounds = statsError{"Input is outside of range."} // ErrSize Must be the same length ErrSize = statsError{"Must be the same length."} // ErrInfValue Value is infinite ErrInfValue = statsError{"Value is infinite."} // ErrYCoord Y Value must be greater than zero ErrYCoord = statsError{"Y Value must be greater than zero."} ) ``` These are the package-wide error values. All error identification should use these values. <a href="https://github.com/golang/go/wiki/Errors#naming">https://github.com/golang/go/wiki/Errors#naming</a> ``` go var ( EmptyInputErr = ErrEmptyInput NaNErr = ErrNaN NegativeErr = ErrNegative ZeroErr = ErrZero BoundsErr = ErrBounds SizeErr = ErrSize InfValue = ErrInfValue YCoordErr = ErrYCoord EmptyInput = ErrEmptyInput ) ``` Legacy error names that didn't start with Err ``` go func AutoCorrelation(data Float64Data, lags int) (float64, error) ``` AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay ``` go func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) ``` ChebyshevDistance computes the Chebyshev distance between two data sets ``` go func Correlation(data1, data2 Float64Data) (float64, error) ``` Correlation describes the degree of relationship between two sets of data ``` go func Covariance(data1, data2 Float64Data) (float64, error) ``` Covariance is a measure of how much two sets of data change ``` go func CovariancePopulation(data1, data2 Float64Data) (float64, error) ``` CovariancePopulation computes covariance for entire population between two

``` go func CumulativeSum(input Float64Data) ([]float64, error) ``` CumulativeSum calculates the cumulative sum of the input slice ``` go func Entropy(input Float64Data) (float64, error) ``` Entropy provides calculation of the entropy ``` go func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) ``` EuclideanDistance computes the Euclidean distance between two data sets ``` go func ExpGeom(p float64) (exp float64, err error) ``` ProbGeom generates the expectation or average number of trials for a geometric random variable with parameter p ``` go func GeometricMean(input Float64Data) (float64, error) ``` GeometricMean gets the geometric mean for a slice of numbers ``` go func HarmonicMean(input Float64Data) (float64, error) ``` HarmonicMean gets the harmonic mean for a slice of numbers ``` go func InterQuartileRange(input Float64Data) (float64, error) ``` InterQuartileRange finds the range between Q1 and Q3 ``` go func ManhattanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) ``` ManhattanDistance computes the Manhattan distance between two data sets ``` go func Max(input Float64Data) (max float64, err error) ``` Max finds the highest number in a slice ``` go func Mean(input Float64Data) (float64, error) ``` Mean gets the average of a slice of numbers ``` go func Median(input Float64Data) (median float64, err error) ``` Median gets the median number in a slice of numbers ``` go func MedianAbsoluteDeviation(input Float64Data) (mad float64, err error) ``` MedianAbsoluteDeviation finds the median of the absolute deviations from the dataset median ``` go func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) ``` MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median ``` go func Midhinge(input Float64Data) (float64, error) ``` Midhinge finds the average of the first and third quartiles ``` go func Min(input Float64Data) (min float64, err error) ``` Min finds the lowest number in a set of data ``` go func MinkowskiDistance(dataPointX, dataPointY Float64Data, lambda float64) (distance float64, err error) ``` MinkowskiDistance computes the Minkowski distance between two data sets Arguments: dataPointX: First set of data points dataPointY: Second set of data points. Length of both data sets must be equal. lambda: aka p or city blocks; With lambda = 1 returned distance is manhattan distance and lambda = 2; it is euclidean distance. Lambda reaching to infinite - distance would be chebysev distance. Return: Distance or error ``` go func Mode(input Float64Data) (mode []float64, err error) ``` Mode gets the mode [most frequent value(s)] of a slice of float64s ``` go func Ncr(n, r int) int ``` Ncr is an N choose R algorithm. Aaron Cannon's algorithm. ``` go func NormBoxMullerRvs(loc float64, scale float64, size int) []float64 ``` NormBoxMullerRvs generates random variates using the BoxMuller transform. For more information please visit: <a href="http://mathworld.wolfram.com/Box-MullerTransformation.html">http://mathworld.wolfram.com/Box-MullerTransformation.html</a> ``` go func NormCdf(x float64, loc float64, scale float64) float64 ``` NormCdf is the cumulative distribution function. ``` go func NormEntropy(loc float64, scale float64) float64 ``` NormEntropy is the differential entropy of the RV. ``` go func NormFit(data []float64) [2]float64 ``` NormFit returns the maximum likelihood estimators for the Normal Distribution. Takes array of float64 values. Returns array of Mean followed by Standard Deviation. ``` go func NormInterval(alpha float64, loc float64, scale float64) [2]float64 ``` NormInterval finds endpoints of the range that contains alpha percent of the distribution. ``` go func NormIsf(p float64, loc float64, scale float64) (x float64) ``` NormIsf is the inverse survival function (inverse of sf). ``` go func NormLogCdf(x float64, loc float64, scale float64) float64 ``` NormLogCdf is the log of the cumulative distribution function. ``` go func NormLogPdf(x float64, loc float64, scale float64) float64 ``` NormLogPdf is the log of the probability density function. ``` go func NormLogSf(x float64, loc float64, scale float64) float64 ``` NormLogSf is the log of the survival function. ``` go func NormMean(loc float64, scale float64) float64 ``` NormMean is the mean/expected value of the distribution. ``` go func NormMedian(loc float64, scale float64) float64 ``` NormMedian is the median of the distribution. ``` go func NormMoment(n int, loc float64, scale float64) float64 ``` NormMoment approximates the non-central (raw) moment of order n. For more information please visit: <a href="https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution">https://math.stackexchange.com/questions/1945448/methods-for-finding-raw-moments-of-the-normal-distribution</a> ``` go func NormPdf(x float64, loc float64, scale float64) float64 ``` NormPdf is the probability density

``` go func NormPpf(p float64, loc float64, scale float64) (x float64) ``` NormPpf is the point percentile function. This is based on Peter John Acklam's inverse normal CDF. algorithm: <a href="http://home.online.no/~pjacklam/notes/invnorm/">http://home.online.no/~pjacklam/notes/invnorm/</a> (no longer visible). For more information please visit: <a href="https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/">https://stackedboxes.org/2017/05/01/acklams-normal-quantile-function/</a> ``` go func NormPpfRvs(loc float64, scale float64, size int) []float64 ``` NormPpfRvs generates random variates using the Point Percentile Function. For more information please visit: <a href="https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/">https://demonstrations.wolfram.com/TheMethodOfInverseTransforms/</a> ``` go func NormSf(x float64, loc float64, scale float64) float64 ``` NormSf is the survival function (also defined as 1 - cdf, but sf is sometimes more accurate). ``` go func NormStats(loc float64, scale float64, moments string) []float64 ``` NormStats returns the mean, variance, skew, and/or kurtosis. Mean(m), variance(v), skew(s), and/or kurtosis(k). Takes string containing any of 'mvsk'. Returns array of m v s k in that order. ``` go func NormStd(loc float64, scale float64) float64 ``` NormStd is the standard deviation of the distribution. ``` go func NormVar(loc float64, scale float64) float64 ``` NormVar is the variance of the distribution. ``` go func Pearson(data1, data2 Float64Data) (float64, error) ``` Pearson calculates the Pearson product-moment correlation coefficient between two variables ``` go func Percentile(input Float64Data, percent float64) (percentile float64, err error) ``` Percentile finds the relative standing in a slice of floats ``` go func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) ``` PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method ``` go func PopulationVariance(input Float64Data) (pvar float64, err error) ``` PopulationVariance finds the amount of variance within a population ``` go func ProbGeom(a int, b int, p float64) (prob float64, err error) ``` ProbGeom generates the probability for a geometric random variable with parameter p to achieve success in the interval of [a, b] trials See <a href="https://en.wikipedia.org/wiki/Geometricdistribution">https://en.wikipedia.org/wiki/Geometricdistribution</a> for more information ``` go func Round(input float64, places int) (rounded float64, err error) ``` Round a float to a specific decimal place or precision ``` go func Sample(input Float64Data, takenum int, replacement bool) ([]float64, error) ``` Sample returns sample from input with replacement or without ``` go func SampleVariance(input Float64Data) (svar float64, err error) ``` SampleVariance finds the amount of variance within a sample ``` go func Sigmoid(input Float64Data) ([]float64, error) ``` Sigmoid returns the input values in the range of -1 to 1 along the sigmoid or s-shaped curve, commonly used in machine learning while training neural networks as an activation function. ``` go func SoftMax(input Float64Data) ([]float64, error) ``` SoftMax returns the input values in the range of 0 to 1 with sum of all the probabilities being equal to one. It is commonly used in machine learning neural networks. ``` go func StableSample(input Float64Data, takenum int) ([]float64, error) ``` StableSample like stable sort, it returns samples from input while keeps the order of original

``` go func StandardDeviation(input Float64Data) (sdev float64, err error) ``` StandardDeviation the amount of variation in the dataset ``` go func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) ``` StandardDeviationPopulation finds the amount of variation from the population ``` go func StandardDeviationSample(input Float64Data) (sdev float64, err error) ``` StandardDeviationSample finds the amount of variation from a sample ``` go func StdDevP(input Float64Data) (sdev float64, err error) ``` StdDevP is a shortcut to StandardDeviationPopulation ``` go func StdDevS(input Float64Data) (sdev float64, err error) ``` StdDevS is a shortcut to StandardDeviationSample ``` go func Sum(input Float64Data) (sum float64, err error) ``` Sum adds all the numbers of a slice together ``` go func Trimean(input Float64Data) (float64, error) ``` Trimean finds the average of the median and the midhinge ``` go func VarGeom(p float64) (exp float64, err error) ``` ProbGeom generates the variance for number for a geometric random variable with parameter p ``` go func VarP(input Float64Data) (sdev float64, err error) ``` VarP is a shortcut to PopulationVariance ``` go func VarS(input Float64Data) (sdev float64, err error) ``` VarS is a shortcut to SampleVariance ``` go func Variance(input Float64Data) (sdev float64, err error) ``` Variance the amount of variation in the dataset ``` go type Coordinate struct { X, Y float64 } ``` Coordinate holds the data in a series ``` go func ExpReg(s []Coordinate) (regressions []Coordinate, err error) ``` ExpReg is a shortcut to ExponentialRegression ``` go func LinReg(s []Coordinate) (regressions []Coordinate, err error) ``` LinReg is a shortcut to LinearRegression ``` go func LogReg(s []Coordinate) (regressions []Coordinate, err error) ``` LogReg is a shortcut to LogarithmicRegression ``` go type Float64Data []float64 ``` Float64Data is a named type for []float64 with helper methods ``` go func LoadRawData(raw interface{}) (f Float64Data) ``` LoadRawData parses and converts a slice of mixed data types to floats ``` go func (f Float64Data) AutoCorrelation(lags int) (float64, error) ``` AutoCorrelation is the correlation of a signal with a delayed copy of itself as a function of delay ``` go func (f Float64Data) Correlation(d Float64Data) (float64, error) ``` Correlation describes the degree of relationship between two sets of data ``` go func (f Float64Data) Covariance(d Float64Data) (float64, error) ``` Covariance is a measure of how much two sets of data change ``` go func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error) ``` CovariancePopulation computes covariance for entire population between two variables ``` go func (f Float64Data) CumulativeSum() ([]float64, error) ``` CumulativeSum returns the cumulative sum of the data ``` go func (f Float64Data) Entropy() (float64, error) ``` Entropy provides calculation of the entropy ``` go func (f Float64Data) GeometricMean() (float64, error) ``` GeometricMean returns the median of the data ``` go func (f Float64Data) Get(i int) float64 ``` Get item in slice ``` go func (f Float64Data) HarmonicMean() (float64, error) ``` HarmonicMean returns the mode of the data ``` go func (f Float64Data) InterQuartileRange() (float64, error) ``` InterQuartileRange finds the range between Q1 and Q3 ``` go func (f Float64Data) Len() int ``` Len returns length of slice ``` go func (f Float64Data) Less(i, j int) bool ``` Less returns if one number is less than another ``` go func (f Float64Data) Max() (float64, error) ``` Max returns the maximum number in the data ``` go func (f Float64Data) Mean() (float64, error) ``` Mean returns the mean of the data ``` go func (f Float64Data) Median() (float64, error) ``` Median returns the median of the data ``` go func (f Float64Data) MedianAbsoluteDeviation() (float64, error) ``` MedianAbsoluteDeviation the median of the absolute deviations from the dataset median ``` go func (f Float64Data) MedianAbsoluteDeviationPopulation() (float64, error) ``` MedianAbsoluteDeviationPopulation finds the median of