-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatutils.go
More file actions
52 lines (42 loc) · 1.17 KB
/
statutils.go
File metadata and controls
52 lines (42 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package betterpath
import (
"math"
)
// StdDeviation returns the standard deviation of the distances
func StdDeviation(distances []float64, mean float64, zeroDistances int) float64 {
std := 0.0
for _, d := range distances {
abs := math.Abs(d - mean)
std += abs * abs
}
std /= float64(len(distances)) - float64(zeroDistances)
std = math.Sqrt(std)
return std
}
// Mean returns the mean of the non-zero distances
func Mean(distances []float64, zeroDistances int) float64 {
mean := 0.0
for _, d := range distances {
mean += d
}
mean /= float64(len(distances)) - float64(zeroDistances)
return mean
}
// Distance returns the distance between two points
func Distance(a Point, b Point) float64 {
return math.Sqrt(math.Pow((a.x-b.x), 2) + math.Pow((a.y-b.y), 2))
}
// Distances returns an array of distances and the number of zero distances
func Distances(points Points) ([]float64, int) {
distances := make([]float64, len(points)-1)
iterDistance := 0.0
zeroDistances := 0
for i := 0; i < len(points)-1; i++ {
iterDistance = Distance(points[i+1], points[i])
if iterDistance == 0 {
zeroDistances++
}
distances[i] = iterDistance
}
return distances, zeroDistances
}