Пример #1
0
func sqrDiff(x1, x2 gotypes.Value) float64 {
	result := 0.0
	if x1.Type() == gotypes.Array {
		a := x1.Array()
		b := x1.Array()
		for i := range a {
			t := a[i].Real() - b[i].Real()
			result += t * t
		}
	} else {
		result = x1.Real() - x2.Real()
		result *= result
	}
	return result
}
Пример #2
0
func gaussian(x, m, s gotypes.Value) float64 {
	s2 := s.Real() * s.Real()
	top := math.Exp(-sqrDiff(x, m) / (2.0 * s2))
	bottom := math.Sqrt(math.Pi * 2 * s2)
	return top / bottom
}