示例#1
0
文件: svm.go 项目: StepLg/go-svm
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]
}
示例#2
0
文件: basicsmo.go 项目: StepLg/go-svm
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
}