func (t *sequentialMinimalOptimizationTask) UpdateSeparatingHyperplane() { for i, p := range t.points { a := t.alpha[i] * t.target[i] if a != 0 { for k := 0; k < t.dimentions; k++ { t.w[k] += a * p[k] } } } thresholds := make([]float, t.size) for i, p := range t.points { thresholds[i] = scalarProduct(t.w, p) - t.target[i] } sort.SortFloats(thresholds) t.w0 = thresholds[len(thresholds)/2] }
func makeClassificateVector(points [][]float, target []float, alpha []float) ([]float, float) { w := make([]float, len(points[0])) for i := 0; i < len(points); i++ { if alpha[i] > 0 { for k := 0; k < len(w); k++ { w[k] += target[i] * alpha[i] * points[i][k] } } } // todo: median thresholds := make([]float, len(alpha)) for i, p := range points { thresholds[i] = prod(w, p) - target[i] } sort.SortFloats(thresholds) w0 := thresholds[len(thresholds)/2] return w, w0 }