func ClassifyNB(vec2Classify []int, p0Vec []float64, p1Vec []float64, pClass1 float64) int { p1 := calc.MultipyIntVec(vec2Classify, p1Vec) p0 := calc.MultipyIntVec(vec2Classify, p0Vec) p1Val := calc.SumFloat(p1) p0Val := calc.SumFloat(p0) p1Val += math.Log(pClass1) p0Val += math.Log(1.0 - pClass1) if p1Val > p0Val { return 1 } else { return 0 } }
func Test_SumFloat(t *testing.T) { a := []float64{1.23, 3.24, 4.65} result := calc.SumFloat(a) t.Log(result) if result > 9.2 || result < 9.0 { t.Fatalf("Sum with the wrong value") } }