Documentation ¶
Index ¶
- func Abs[N Number](float N) N
- func AutoCorrelation[F constraints.Float](lags int, data ...F) F
- func Ceil[F constraints.Float](float F) F
- func ChebyshevDistance[N Number](dataPointX, dataPointY []N) N
- func Clone[T any](elems []T) []T
- func Correlation[F constraints.Float](floats1, floats2 []F) F
- func Covariance[F constraints.Float](floats1, floats2 []F) F
- func CovariancePopulation[F constraints.Float](floats1, floats2 []F) F
- func CumulativeSum[O constraints.Ordered](ordereds ...O) []O
- func Empty[T any]() T
- func Entropy[F constraints.Float](floats ...F) F
- func EuclideanDistance[N Number](dataPointX, dataPointY []N) float64
- func Exp[N Number](number N) N
- func ExpGeom[F constraints.Float](float F) F
- func Floor[F constraints.Float](float F) F
- func GeometricMean[F constraints.Float](floats ...F) F
- func HarmonicMean[F constraints.Float](floats ...F) F
- func InterQuartileRange[N Number](numbers ...N) N
- func Log[F constraints.Float](float F) F
- func ManhattanDistance[N Number](dataPointX, dataPointY []N) N
- func Max[O constraints.Ordered](ordereds ...O) O
- func Mean[N Number](numbers ...N) N
- func Median[O Number](ordereds ...O) O
- func MedianAbsoluteDeviation[F constraints.Float](floats ...F) F
- func MedianAbsoluteDeviationPopulation[F constraints.Float](floats ...F) F
- func Midhinge[N Number](numbers ...N) N
- func Min[O constraints.Ordered](ordereds ...O) O
- func MinkowskiDistance[N Number](dataPointX, dataPointY []N, lambda float64) float64
- func Mode[N Number](numbers ...N) []N
- func Modf[F constraints.Float](float F) (F, F)
- func Normalize[F constraints.Float](floats []F)
- func Pearson[F constraints.Float](floats1, floats2 []F) F
- func Percentile[N Number](percent float64, numbers ...N) N
- func PercentileNearestRank[N Number](percent float64, numbers ...N) N
- func PopulationVariance[F constraints.Float](floats ...F) F
- func Pow[N Number](x, y N) N
- func ProbGeom[F constraints.Float](start int, end int, float F) F
- func Round[F constraints.Float](float F, places int) F
- func Sample[T any](elems ...T) T
- func SampleVariance[F constraints.Float](floats ...F) F
- func Samples[T any](takenum int, replacement bool, elems ...T) []T
- func Sigmoid[F constraints.Float](floats ...F) []F
- func SoftMax[F constraints.Float](floats ...F) []F
- func Sort[O constraints.Ordered](ordereds []O)
- func Sorted[O constraints.Ordered](ordereds []O) bool
- func SortedClone[O constraints.Ordered](ordereds []O) []O
- func SortedCloneDif[O constraints.Ordered](ordereds []O) []O
- func Sqrt[F constraints.Float](float F) F
- func StableSamples[T any](takenum int, elems ...T) []T
- func StandardDeviation[F constraints.Float](floats ...F) F
- func StandardDeviationPopulation[F constraints.Float](floats ...F) F
- func StandardDeviationSample[F constraints.Float](floats ...F) F
- func StdDevP[F constraints.Float](floats ...F) F
- func StdDevS[F constraints.Float](floats ...F) F
- func Sum[O constraints.Ordered](ordereds ...O) O
- func Trimean[N Number](input ...N) N
- func VarGeom[F constraints.Float](float F) F
- func VarP[F constraints.Float](floats ...F) F
- func VarS[F constraints.Float](floats ...F) F
- func Variance[F constraints.Float](floats ...F) F
- func VarianceBySample[F constraints.Float](sample int, floats ...F) F
- type Coordinate
- type Number
- type Ordered
- type Outliers
- type Quartiles
- type Series
Examples ¶
- AutoCorrelation
- ChebyshevDistance
- Covariance
- CovariancePopulation
- CumulativeSum
- Entropy
- EuclideanDistance
- ExpGeom
- ExpReg
- ExponentialRegression
- GeometricMean
- HarmonicMean
- InterQuartileRange
- LinReg
- LinearRegression
- LinearRegression (Int)
- LogReg
- LogarithmicRegression
- ManhattanDistance
- Max
- Mean
- Median
- MedianAbsoluteDeviation
- Midhinge
- Min
- MinkowskiDistance
- Mode
- Normalize
- Normalize (Inf)
- Pearson
- Percentile
- PercentileNearestRank
- PopulationVariance
- Pow
- ProbGeom
- Quartile
- QuartileOutliers
- Round
- Sample
- SampleVariance
- Samples
- Sigmoid
- SoftMax
- Sort
- Sorted
- Sqrt
- StableSamples
- StandardDeviation
- StandardDeviationSample
- StdDevP
- StdDevS
- Sum
- Trimean
- VarGeom
- VarP
- VarS
- Variance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoCorrelation ¶
func AutoCorrelation[F constraints.Float](lags int, data ...F) F
AutoCorrelation returns the correlation of a signal with a delayed copy of itself as a function of delay.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.AutoCorrelation(1, []float64{1, 2, 3, 4, 5}...)) fmt.Println(kstats.AutoCorrelation(1, []float64{}...)) }
Output: 0.4 0
func Ceil ¶
func Ceil[F constraints.Float](float F) F
func ChebyshevDistance ¶
func ChebyshevDistance[N Number](dataPointX, dataPointY []N) N
ChebyshevDistance returns the Chebyshev distance between two data sets.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.ChebyshevDistance([]int{2, 3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2})) fmt.Println(kstats.ChebyshevDistance([]int{3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2})) }
Output: 6 0
func Correlation ¶
func Correlation[F constraints.Float](floats1, floats2 []F) F
Correlation returns the degree of relationship between two sets of floats.
func Covariance ¶
func Covariance[F constraints.Float](floats1, floats2 []F) F
Covariance returns a measure of how much two floats of data change.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Covariance([]float64{1, 2, 3, 4, 5}, []float64{1, 2, 3, 5, 6})) fmt.Println(kstats.Covariance([]float64{2, 3, 4, 5}, []float64{1, 2, 3, 5, 6})) }
Output: 3.2499999999999996 0
func CovariancePopulation ¶
func CovariancePopulation[F constraints.Float](floats1, floats2 []F) F
CovariancePopulation returns covariance for entire population between two floats.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.CovariancePopulation([]float64{1, 2, 3.5, 3.7, 8, 12}, []float64{0.5, 1, 2.1, 3.4, 3.4, 4})) fmt.Println(kstats.CovariancePopulation([]float64{2, 3.5, 3.7, 8, 12}, []float64{0.5, 1, 2.1, 3.4, 3.4, 4})) }
Output: 4.191666666666666 0
func CumulativeSum ¶
func CumulativeSum[O constraints.Ordered](ordereds ...O) []O
CumulativeSum return the cumulative sum of ordereds.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.CumulativeSum(1.0, 2.1, 3.2, 4.823, 4.1, 5.8)) fmt.Println(kstats.CumulativeSum([]int{}...)) fmt.Println(kstats.CumulativeSum("a", "b", "c")) }
Output: [1 3.1 6.300000000000001 11.123000000000001 15.223 21.023] [] [a ab abc]
func Entropy ¶
func Entropy[F constraints.Float](floats ...F) F
Entropy returns entropy of floats.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Entropy(0.0, 1.1, 2.2, 3.3)) }
Output: 1.0114042647073518
func EuclideanDistance ¶
EuclideanDistance returns the Euclidean distance between two data sets.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.EuclideanDistance([]int{2, 3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2})) fmt.Println(kstats.EuclideanDistance([]int{3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2})) }
Output: 10.583005244258363 NaN
func ExpGeom ¶
func ExpGeom[F constraints.Float](float F) F
ProbGeom returns the expectation or average number of trials for a geometric random variable with parameter float.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.ExpGeom(0.5)) fmt.Println(kstats.ExpGeom(1.5)) }
Output: 2 0
func Floor ¶
func Floor[F constraints.Float](float F) F
func GeometricMean ¶
func GeometricMean[F constraints.Float](floats ...F) F
GeometricMean returns the geometric mean for floats.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.GeometricMean(2.0, 18.0)) fmt.Println(kstats.GeometricMean([]float32{}...)) }
Output: 6 0
func HarmonicMean ¶
func HarmonicMean[F constraints.Float](floats ...F) F
HarmonicMean return the harmonic mean for floats.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(kstats.HarmonicMean(1.0, 2.0, 3.0, 4.0, 5.0), 2)) fmt.Println(kstats.HarmonicMean([]float32{}...)) fmt.Println(kstats.Round(kstats.HarmonicMean(0.0), 2)) }
Output: 2.19 0 0
func InterQuartileRange ¶
func InterQuartileRange[N Number](numbers ...N) N
InterQuartileRange returns the range between Q1 and Q3.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.InterQuartileRange(102, 104, 105, 107, 108, 109, 110, 112, 115, 116, 118)) fmt.Println(kstats.InterQuartileRange([]int{}...)) }
Output: 10 0
func Log ¶
func Log[F constraints.Float](float F) F
func ManhattanDistance ¶
func ManhattanDistance[N Number](dataPointX, dataPointY []N) N
ManhattanDistance returns the Manhattan distance between two data sets.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.ManhattanDistance([]int{2, 3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2})) fmt.Println(kstats.ManhattanDistance([]int{3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2})) }
Output: 24 0
func Max ¶
func Max[O constraints.Ordered](ordereds ...O) O
Max returns the highest elem in ordereds.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Max(9.1, 1.0, 2.2, 30.2, 4.0)) fmt.Println(kstats.Max([]int{}...)) }
Output: 30.2 0
func Mean ¶
func Mean[N Number](numbers ...N) N
Mean returns the average of numbers.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Mean(1, 2, 3, 6)) fmt.Println(kstats.Mean([]int{}...)) }
Output: 3 0
func Median ¶
func Median[O Number](ordereds ...O) O
Median return the median elem of ordereds.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Median(5, 3, 4, 2, 1)) fmt.Println(kstats.Median(6.0, 3.0, 2.0, 4.0, 5.0, 1.0)) fmt.Println(kstats.Median(1)) fmt.Println(kstats.Median([]int{}...)) }
Output: 3 3.5 1 0
func MedianAbsoluteDeviation ¶
func MedianAbsoluteDeviation[F constraints.Float](floats ...F) F
MedianAbsoluteDeviation returns the median of the absolute deviations from the floats median.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.MedianAbsoluteDeviation([]float64{1, 2, 3}...)) fmt.Println(kstats.MedianAbsoluteDeviation([]float64{}...)) }
Output: 1 0
func MedianAbsoluteDeviationPopulation ¶
func MedianAbsoluteDeviationPopulation[F constraints.Float](floats ...F) F
MedianAbsoluteDeviationPopulation returns the median of the absolute deviations from the population median.
func Midhinge ¶
func Midhinge[N Number](numbers ...N) N
Midhinge returns the average of the first and third quartiles.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Midhinge[float32](1, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13)) fmt.Println(kstats.Midhinge([]int{}...)) }
Output: 7.5 0
func Min ¶
func Min[O constraints.Ordered](ordereds ...O) O
Min returns the lowest elem in ordereds.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Min(9, 1, 2, 3, 4)) fmt.Println(kstats.Min([]int{}...)) }
Output: 1 0
func MinkowskiDistance ¶
MinkowskiDistance returns the Minkowski distance between two data sets.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.MinkowskiDistance([]int{2, 3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2}, 1.0)) fmt.Println(kstats.MinkowskiDistance([]int{3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2}, 1.0)) fmt.Println(kstats.MinkowskiDistance([]int{}, []int{8, 7, 6, 5, 4, 3, 2}, 1.0)) fmt.Println(kstats.MinkowskiDistance([]int{2, 3, 4, 5, 6, 7, 8}, []int{8, 7, 6, 5, 4, 3, 2}, 0)) }
Output: 24 NaN NaN NaN
func Mode ¶
func Mode[N Number](numbers ...N) []N
Mode returns the mode [most frequent value(s)] of a slice of numbers.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Mode(2.0, 2.0, 2.0, 2.0)) fmt.Println(kstats.Mode([]float64{5, 3, 4, 2, 1}...)) fmt.Println(kstats.Mode([]float64{-50, -46.325, -46.325, -.87, 1, 2.1122, 3.20, 5, 15, 15, 15.0001}...)) fmt.Println(kstats.Mode([]float64{}...)) fmt.Println(kstats.Mode([]float64{2.0}...)) }
Output: [2] [] [-46.325 15] [] [2]
func Modf ¶
func Modf[F constraints.Float](float F) (F, F)
func Normalize ¶
func Normalize[F constraints.Float](floats []F)
Normalize floats to normalized.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { list := []float32{2, 2, 4} kstats.Normalize(list) fmt.Println(list) }
Output: [0.25 0.25 0.5]
Example (Inf) ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { list := []float32{2, -2} kstats.Normalize(list) fmt.Println(list) }
Output: [+Inf -Inf]
func Pearson ¶
func Pearson[F constraints.Float](floats1, floats2 []F) F
Pearson returns the Pearson product-moment correlation coefficient between two variables.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { floats1 := []float64{1, 2, 3, 4, 5} floats2 := []float64{1, 2, 3, 5, 6} fmt.Println(kstats.Round(kstats.Pearson(floats1, floats2), 5)) fmt.Println(kstats.Pearson(floats1, []float64{})) fmt.Println(kstats.Pearson([]float64{0}, []float64{0})) }
Output: 0.99124 0 0
func Percentile ¶
Percentile returns the relative standing in a slice of numbers.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Percentile(90, 63, 54, 61, 62, 66)) fmt.Println(kstats.Percentile(90, 43)) fmt.Println(kstats.Percentile(90, []int{}...)) fmt.Println(kstats.Percentile(190, 3, 2)) fmt.Println(kstats.Percentile(0.2, 3, 2)) fmt.Println(kstats.Percentile(10, 3, 1, 2, 3, 4, 5, 6, 7, 8, 9)) }
Output: 64 43 0 0 0 1
func PercentileNearestRank ¶
PercentileNearestRank returns the relative standing in a slice of floats using the Nearest Rank method.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.PercentileNearestRank(0, 1, 2, 3)) fmt.Println(kstats.PercentileNearestRank(30, 35, 20, 15, 40, 50)) fmt.Println(kstats.PercentileNearestRank(190, 3, 2)) fmt.Println(kstats.PercentileNearestRank(90, []int{}...)) fmt.Println(kstats.PercentileNearestRank(100, 3, 2)) }
Output: 1 20 0 0 3
func PopulationVariance ¶
func PopulationVariance[F constraints.Float](floats ...F) F
PopulationVariance returns the amount of floats within a population.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(kstats.PopulationVariance(1.0, 2.0, 3.0), 1)) }
Output: 0.7
func Pow ¶
func Pow[N Number](x, y N) N
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Pow(2, 3)) fmt.Println(kstats.Pow(4.0, 0.5)) }
Output: 8 2
func ProbGeom ¶
func ProbGeom[F constraints.Float](start int, end int, float F) F
ProbGeom returns the probability for a geometric random variable with parameter float to achieve success in the interval of [start, end] trials See https://en.wikipedia.org/wiki/Geometric_distribution for more information.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.ProbGeom(1, 2, 0.5)) fmt.Println(kstats.ProbGeom(2, 1, 0.5)) }
Output: 0.25 0
func Round ¶
func Round[F constraints.Float](float F, places int) F
Round returns a float to a specific decimal place or precision.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(3.1415926, 2)) fmt.Println(kstats.Round(-3.005926, 2)) }
Output: 3.14 -3.01
func Sample ¶
func Sample[T any](elems ...T) T
Samples returns sample of elems.
Example ¶
package main import ( "fmt" "math/rand" "github.com/xuender/kstats" ) func main() { rand.Seed(0) fmt.Println(kstats.Sample(0, 1, 2, 3)) fmt.Println(kstats.Sample(1)) fmt.Println(kstats.Sample([]int{}...)) }
Output: 2 1 0
func SampleVariance ¶
func SampleVariance[F constraints.Float](floats ...F) F
SampleVariance returns the amount of floats within a sample.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.SampleVariance(1.0, 2.0, 3.0)) }
Output: 1
func Samples ¶
Samples returns sample from elems with replacement or without.
Example ¶
package main import ( "fmt" "math/rand" "github.com/xuender/kstats" ) func main() { rand.Seed(0) fmt.Println(kstats.Samples(3, true, 0, 1, 2, 3)) fmt.Println(kstats.Samples(3, false, 0, 1, 2, 3)) fmt.Println(kstats.Samples(30, false, 0, 1, 2, 3)) fmt.Println(kstats.Samples(30, false, []int{}...)) }
Output: [2 2 1] [0 2 1] [3 0 1 2] []
func Sigmoid ¶
func Sigmoid[F constraints.Float](floats ...F) []F
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.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Sigmoid(3.0, 1.0, 2.1)) fmt.Println(kstats.Sigmoid([]float32{}...)) }
Output: [0.9525741268224334 0.7310585786300049 0.8909031788043871] []
func SoftMax ¶
func SoftMax[F constraints.Float](floats ...F) []F
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.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.SoftMax(3.0, 1.0, 0.2)) fmt.Println(kstats.SoftMax([]float32{}...)) }
Output: [0.8360188027814407 0.11314284146556013 0.05083835575299916] []
func Sort ¶
func Sort[O constraints.Ordered](ordereds []O)
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { ints := []int{4, 3, 1, 2} kstats.Sort(ints) fmt.Println(ints) }
Output: [1 2 3 4]
func Sorted ¶
func Sorted[O constraints.Ordered](ordereds []O) bool
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Sorted([]int{1, 2, 3})) fmt.Println(kstats.Sorted([]int{1, 2, 3, 0})) }
Output: true false
func SortedClone ¶
func SortedClone[O constraints.Ordered](ordereds []O) []O
func SortedCloneDif ¶
func SortedCloneDif[O constraints.Ordered](ordereds []O) []O
func Sqrt ¶
func Sqrt[F constraints.Float](float F) F
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Sqrt(9.0)) }
Output: 3
func StableSamples ¶
StableSamples returns samples keeps the order of original elems.
Example ¶
package main import ( "fmt" "math/rand" "github.com/xuender/kstats" ) func main() { rand.Seed(0) fmt.Println(kstats.StableSamples(3, 0, 1, 2, 3)) fmt.Println(kstats.StableSamples(30, 0, 1, 2, 3)) fmt.Println(kstats.StableSamples(30, []int{}...)) }
Output: [1 2 3] [0 1 2 3] []
func StandardDeviation ¶
func StandardDeviation[F constraints.Float](floats ...F) F
StandardDeviation returns the amount of variation in the floats.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(kstats.StandardDeviation([]float64{1, 2, 3}...), 2)) fmt.Println(kstats.StandardDeviation([]float64{}...)) }
Output: 0.82 0
func StandardDeviationPopulation ¶
func StandardDeviationPopulation[F constraints.Float](floats ...F) F
StandardDeviationPopulation returns the amount of variation from the population.
func StandardDeviationSample ¶
func StandardDeviationSample[F constraints.Float](floats ...F) F
StandardDeviationSample returns the amount of variation from a sample.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.StandardDeviationSample([]float64{1, 2, 3}...)) fmt.Println(kstats.StandardDeviationSample([]float64{}...)) }
Output: 1 0
func StdDevP ¶
func StdDevP[F constraints.Float](floats ...F) F
StdDevP is a shortcut to StandardDeviationPopulation.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(kstats.StdDevP([]float64{1, 2, 3}...), 2)) }
Output: 0.82
func StdDevS ¶
func StdDevS[F constraints.Float](floats ...F) F
StdDevS is a shortcut to StandardDeviationSample.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.StdDevS([]float64{1, 2, 3}...)) }
Output: 1
func Sum ¶
func Sum[O constraints.Ordered](ordereds ...O) O
Sum returns the sum of ordereds.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Sum(1, 2, 3, 4)) fmt.Println(kstats.Sum("a", "b", "c")) }
Output: 10 abc
func Trimean ¶
func Trimean[N Number](input ...N) N
Trimean returns the average of the median and the midhinge.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Trimean[float64](1, 3, 4, 4, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 12, 13)) fmt.Println(kstats.Trimean([]int{}...)) }
Output: 7.25 0
func VarGeom ¶
func VarGeom[F constraints.Float](float F) F
ProbGeom returns the variance for number for a geometric random variable with parameter float.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.VarGeom(0.5)) fmt.Println(kstats.VarGeom(11.0)) }
Output: 2 0
func VarP ¶
func VarP[F constraints.Float](floats ...F) F
VarP is a shortcut to PopulationVariance.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(kstats.VarP(1.0, 2.0, 3.0), 1)) }
Output: 0.7
func VarS ¶
func VarS[F constraints.Float](floats ...F) F
VarS is a shortcut to SampleVariance.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.VarS(1.0, 2.0, 3.0)) }
Output: 1
func Variance ¶
func Variance[F constraints.Float](floats ...F) F
Variance returns amount of variation in the floats.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Round(kstats.Variance(1.0, 2.0, 3.0), 1)) fmt.Println(kstats.Variance([]float64{}...)) }
Output: 0.7 0
func VarianceBySample ¶
func VarianceBySample[F constraints.Float](sample int, floats ...F) F
VarianceBySample return amount of variation in the floats by sample.
Types ¶
type Coordinate ¶
Coordinate holds the data in a series.
func ExpReg ¶
func ExpReg[N, F Number](s []Coordinate[N, F]) []Coordinate[N, float64]
ExpReg is a shortcut to ExponentialRegression.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, float64]{ {1, 2.3}, {2, 3.3}, {3, 3.7}, {4, 4.3}, {5, 5.3}, } fmt.Println(kstats.ExpReg(data)) }
Output: [{1 2.5150181024736638} {2 3.032084111136781} {3 3.6554544271334493} {4 4.406984298281804} {5 5.313022222665875}]
func LinReg ¶
func LinReg[N, F Number](s []Coordinate[N, F]) []Coordinate[N, float64]
LinReg is a shortcut to LinearRegression.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, int]{ {1, 2}, {2, 3}, {3, 3}, } fmt.Println(kstats.LinReg(data)) }
Output: [{1 2.1666666666666665} {2 2.6666666666666665} {3 3.1666666666666665}]
func LogReg ¶
func LogReg[N, F Number](s []Coordinate[N, F]) []Coordinate[N, float64]
LogReg is a shortcut to LogarithmicRegression.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, float64]{ {1, 2.3}, {2, 3.3}, {3, 3.7}, {4, 4.3}, {5, 5.3}, } fmt.Println(kstats.LogReg(data)) }
Output: [{1 2.1520822363811702} {2 3.3305559222492214} {3 4.019918836568674} {4 4.509029608117273} {5 4.888413396683663}]
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
type Ordered ¶
type Ordered[O constraints.Ordered] []O
type Outliers ¶
type Outliers[N Number] struct { Mild []N Extreme []N }
Outliers holds mild and extreme outliers found in data.
func QuartileOutliers ¶
func QuartileOutliers[F constraints.Float](floats ...F) Outliers[F]
QuartileOutliers returns the mild and extreme outliers.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.QuartileOutliers[float64](-1000, 1, 3, 4, 4, 6, 6, 6, 6, 7, 8, 15, 18, 100)) fmt.Println(kstats.QuartileOutliers([]float64{}...)) }
Output: {[15 18] [-1000 100]} {[] []}
type Quartiles ¶
type Quartiles[N Number] struct { Q1 N Q2 N Q3 N }
Quartiles holds the three quartile points.
func Quartile ¶
Quartile returns the three quartile points from numbers.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { fmt.Println(kstats.Quartile(6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49)) fmt.Println(kstats.Quartile[float64](7, 15, 36, 39, 40, 41)) fmt.Println(kstats.Quartile([]int{}...)) }
Output: {15 40 43} {15 37.5 40} {0 0 0}
type Series ¶
type Series[N Number, F Number] []Coordinate[N, F]
Series is a container for a series of data.
func ExponentialRegression ¶
ExponentialRegression returns an exponential regression on data series.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, float64]{ {1, 2.3}, {2, 3.3}, {3, 3.7}, {4, 4.3}, {5, 5.3}, } fmt.Println(kstats.ExponentialRegression(data)) fmt.Println(kstats.ExponentialRegression([]kstats.Coordinate[int, float64]{})) fmt.Println(kstats.ExponentialRegression([]kstats.Coordinate[int, float64]{{1, -1}})) }
Output: [{1 2.5150181024736638} {2 3.032084111136781} {3 3.6554544271334493} {4 4.406984298281804} {5 5.313022222665875}] [] []
func LinearRegression ¶
LinearRegression returns the least squares linear regression on data series.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, float64]{ {1, 2.3}, {2, 3.3}, {3, 3.7}, } fmt.Println(kstats.LinearRegression(data)) fmt.Println(kstats.LinearRegression([]kstats.Coordinate[int, float64]{})) }
Output: [{1 2.400000000000001} {2 3.1} {3 3.7999999999999994}] []
Example (Int) ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, int]{ {1, 2}, {2, 3}, {3, 3}, } fmt.Println(kstats.LinearRegression(data)) }
Output: [{1 2.1666666666666665} {2 2.6666666666666665} {3 3.1666666666666665}]
func LogarithmicRegression ¶
LogarithmicRegression returns an logarithmic regression on data series.
Example ¶
package main import ( "fmt" "github.com/xuender/kstats" ) func main() { data := []kstats.Coordinate[int, float64]{ {1, 2.3}, {2, 3.3}, {3, 3.7}, {4, 4.3}, {5, 5.3}, } fmt.Println(kstats.LogarithmicRegression(data)) fmt.Println(kstats.LogarithmicRegression([]kstats.Coordinate[int, float64]{})) }
Output: [{1 2.1520822363811702} {2 3.3305559222492214} {3 4.019918836568674} {4 4.509029608117273} {5 4.888413396683663}] []