from pySVM import * import sys SV=SparseVector v=SV(range(1, 10)) # # classification # cp = ClassificationProblem() cp.reserve(100) ce = ClassificationExample(v, 1) if not ce.label: sys.exit(1) if v - ce.vector: sys.exit(1) cp.append(ce) cp.append(ClassificationExample(-v, 0)) if len(cp) != 2: sys.exit(1) if cp[0].vector -ce.vector: sys.exit(1) if cp[1].vector +v: sys.exit(1) cp.normalize() vv = cp[0].vector sum = reduce(lambda x,y: x+y[1], vv, 0.0) if int(sum) != 9: sys.exit(1) sum = 0 ix = iter(cp) del cp for p in ix: sum += p.label if sum-1.0: sys.exit(1) # # regression # cp = RegressionProblem() cp.reserve(100) ce = RegressionExample(v, 1) if not ce.label: sys.exit(1) if v - ce.vector: sys.exit(1) cp.append(ce) cp.append(RegressionExample(-v, 0)) if len(cp) != 2: sys.exit(1) if cp[0].vector -ce.vector: sys.exit(1) if cp[1].vector +v: sys.exit(1) cp.normalize() vv = cp[0].vector sum = reduce(lambda x,y: x+y[1], vv, 0.0) if int(sum) != 9: sys.exit(1) sum = 0 ix = iter(cp) del cp for p in ix: sum += p.label if sum-1.0: sys.exit(1)