示例#1
0
文件: knn.go 项目: deathly809/goml
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
文件: knn.go 项目: deathly809/goml
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
}