def test_bound_at(): points, labels, C, alphas, bias = three_point_problem() svm = smo.SVM(points, labels, C, alphas, bias) assert svm.bound_at(0) assert not svm.bound_at(1) assert not svm.bound_at(2)
def test_kkt_fails(): points, labels, C, alphas, bias = three_point_problem() svm = smo.SVM(points, labels, C, alphas, bias) assert svm.kkt_fails(0) assert svm.kkt_fails(1) assert svm.kkt_fails(2) assert svm.some_kkt_fails()
def test_select_indices(): points, labels, C, alphas, bias = three_point_problem() svm = smo.SVM(points, labels, C, alphas, bias) assert not svm.eligible_indices assert not svm.eligible_indices_nonbound i1, i2 = svm.select_indices() assert len(svm.eligible_indices) == 2 assert len(svm.eligible_indices_nonbound) == 1 assert i1 == 1 # nonbound assert i2 == 0 # biggest E discrepancy w/ i1
def test_dual_form_evaluate(): points, labels, C, alphas, bias = three_point_problem() w = normalize([3, 1]) svm = smo.SVM(points, labels, C, alphas, bias) assert svm.evaluate(points[0]) < 0 assert svm.evaluate(points[1]) < 0 assert svm.evaluate(points[2]) > 0 assert abs(svm.evaluate(points[0]) - (-1.2649110640673518)) < 1e-8 assert abs(svm.evaluate(points[1]) - (-0.3162277660168379)) < 1e-8 assert abs(svm.evaluate(points[2]) - 0.3162277660168379) < 1e-8 assert dot_product(w, points[0]) + bias == svm.evaluate(points[0]) assert dot_product(w, points[1]) + bias == svm.evaluate(points[1]) assert dot_product(w, points[2]) + bias == svm.evaluate(points[2])
def test_constructor(): w = normalize((random.random(), random.random())) points, labels = zip(*sample_data(w)) smo.SVM(points, labels)