Esempio n. 1
0
// MeanDist computes the mean (μ) and the standard deviation (σ)
// of the spherical distances between point q and points p₀,p₁,...
// on the unit sphere S². This function panics if len(p) ≤ 1.
func MeanDist(q Geo, p []Geo) (μ, σ float64) {
	n := len(p)
	if n < 2 {
		panic("MeanDist: len(p) ≤ 1")
	}

	var sum acc.Accum
	var sum2 acc.Accum2
	for _, t := range p {
		dist := q.Dist(t)
		sum.Add(dist)
		sum2.Add2(dist)
	}

	μ = sum.Value() / float64(n)
	σ = (sum2.Value() - float64(n)*μ*μ) / float64(n-1)
	σ = math.Sqrt(plus(σ))
	return
}
Esempio n. 2
0
// MeanGeo computes the mean direction (m) and the mean resultant length (r)
// of points p₀,p₁,... on the unit sphere S². This function panics if len(p) = 0.
func MeanGeo(p []Geo) (m Geo, r float64) {
	n := len(p)
	if n == 0 {
		panic("MeanGeo: len(p) = 0")
	}

	var accx, accy, accz acc.Accum
	for _, t := range p {
		c := t.c()
		accx.Add(c[0])
		accy.Add(c[1])
		accz.Add(c[2])
	}

	u := vec{accx.Value(), accy.Value(), accz.Value()}
	m = Geo{u.hat()}
	r = u.div(float64(n)).abs()
	if r > 1 {
		r = 1
	}
	return
}