Adding dep files and dependencies.
This commit is contained in:
parent
45f9efa578
commit
b341c0a0e4
539 changed files with 313111 additions and 0 deletions
60
vendor/github.com/montanaflynn/stats/mean.go
generated
vendored
Normal file
60
vendor/github.com/montanaflynn/stats/mean.go
generated
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
package stats
|
||||
|
||||
import "math"
|
||||
|
||||
// Mean gets the average of a slice of numbers
|
||||
func Mean(input Float64Data) (float64, error) {
|
||||
|
||||
if input.Len() == 0 {
|
||||
return math.NaN(), EmptyInput
|
||||
}
|
||||
|
||||
sum, _ := input.Sum()
|
||||
|
||||
return sum / float64(input.Len()), nil
|
||||
}
|
||||
|
||||
// GeometricMean gets the geometric mean for a slice of numbers
|
||||
func GeometricMean(input Float64Data) (float64, error) {
|
||||
|
||||
l := input.Len()
|
||||
if l == 0 {
|
||||
return math.NaN(), EmptyInput
|
||||
}
|
||||
|
||||
// Get the product of all the numbers
|
||||
var p float64
|
||||
for _, n := range input {
|
||||
if p == 0 {
|
||||
p = n
|
||||
} else {
|
||||
p *= n
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the geometric mean
|
||||
return math.Pow(p, 1/float64(l)), nil
|
||||
}
|
||||
|
||||
// HarmonicMean gets the harmonic mean for a slice of numbers
|
||||
func HarmonicMean(input Float64Data) (float64, error) {
|
||||
|
||||
l := input.Len()
|
||||
if l == 0 {
|
||||
return math.NaN(), EmptyInput
|
||||
}
|
||||
|
||||
// Get the sum of all the numbers reciprocals and return an
|
||||
// error for values that cannot be included in harmonic mean
|
||||
var p float64
|
||||
for _, n := range input {
|
||||
if n < 0 {
|
||||
return math.NaN(), NegativeErr
|
||||
} else if n == 0 {
|
||||
return math.NaN(), ZeroErr
|
||||
}
|
||||
p += (1 / n)
|
||||
}
|
||||
|
||||
return float64(l) / p, nil
|
||||
}
|
Reference in a new issue