Adding dep files and dependencies.
This commit is contained in:
parent
45f9efa578
commit
b341c0a0e4
539 changed files with 313111 additions and 0 deletions
47
vendor/github.com/montanaflynn/stats/mode.go
generated
vendored
Normal file
47
vendor/github.com/montanaflynn/stats/mode.go
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
package stats
|
||||
|
||||
// Mode gets the mode [most frequent value(s)] of a slice of float64s
|
||||
func Mode(input Float64Data) (mode []float64, err error) {
|
||||
// Return the input if there's only one number
|
||||
l := input.Len()
|
||||
if l == 1 {
|
||||
return input, nil
|
||||
} else if l == 0 {
|
||||
return nil, EmptyInput
|
||||
}
|
||||
|
||||
c := sortedCopyDif(input)
|
||||
// Traverse sorted array,
|
||||
// tracking the longest repeating sequence
|
||||
mode = make([]float64, 5)
|
||||
cnt, maxCnt := 1, 1
|
||||
for i := 1; i < l; i++ {
|
||||
switch {
|
||||
case c[i] == c[i-1]:
|
||||
cnt++
|
||||
case cnt == maxCnt && maxCnt != 1:
|
||||
mode = append(mode, c[i-1])
|
||||
cnt = 1
|
||||
case cnt > maxCnt:
|
||||
mode = append(mode[:0], c[i-1])
|
||||
maxCnt, cnt = cnt, 1
|
||||
default:
|
||||
cnt = 1
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case cnt == maxCnt:
|
||||
mode = append(mode, c[l-1])
|
||||
case cnt > maxCnt:
|
||||
mode = append(mode[:0], c[l-1])
|
||||
maxCnt = cnt
|
||||
}
|
||||
|
||||
// Since length must be greater than 1,
|
||||
// check for slices of distinct values
|
||||
if maxCnt == 1 {
|
||||
return Float64Data{}, nil
|
||||
}
|
||||
|
||||
return mode, nil
|
||||
}
|
Reference in a new issue