def main():
    input_dir = sys.argv[1]
    num_samples_per_site = int(sys.argv[2])
    target_sites = get_target_sites(input_dir)

    labels = dict(map(lambda (i, s): (s, i), enumerate(target_sites)))

    X, Y = load_feature_vectors(input_dir, num_samples_per_site, labels)
    X, Y, testX, testY = select_test_set(X, Y, (num_samples_per_site / 2) * len(target_sites))

    # X, testX = scale(X, testX)

    X = [[0.0, 0.0], [0.01, 0.01], [1.0, 1.0], [1.1, 1.1], [2.0, 2.0], [2.1, 2.1], [2.05, 2.05]]#, [2.05, 2.05], [2.05, 2.07], [2.01, 2.01]]
    Y=[0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 1.0]#, 1.0, 2.0, 2.0]
    labels = {0: 0, 1: 1, 2: 2}

    thetas, bs, slacks = SVM_fit(X, Y, len(labels), 5.0)

    print "thetas"
    print thetas[0]
    print thetas[1]
    print thetas[2]
    print "bs"
    print bs
    print "slacks"
    print slacks


    print "Should be class 0:"
    print SVM_classify([0.05, 0.05], thetas, bs)
    print "Should be class 1:"
    print SVM_classify([1.05, 1.05], thetas, bs)
    print "Should be class 2:"
    print SVM_classify([1.98, 1.98], thetas, bs)
예제 #2
0
def main():
    cmd = sys.argv[3]
    input_dir = sys.argv[1]
    num_samples_per_site = int(sys.argv[2])
    target_sites = get_target_sites(input_dir)

    labels = dict(map(lambda (i, s): (s, i), enumerate(target_sites)))
    X, Y = load_feature_vectors(input_dir, num_samples_per_site, labels)
    X, Y, testX, testY = select_test_set(X, Y,
                           (num_samples_per_site / 2) * len(target_sites))
    Y = map(lambda v: v*1.0, Y)
    testY = map(lambda v: v*1.0, testY)

    pca = PCA(n_components = 50)

    print "Fitting X"
    pca.fit(X)

    print "Transforming X and testX"
    Xnew = pca.transform(X)
    testXnew = pca.transform(testX)

    del X
    del testX

    if cmd == "monb":
        multiclass_on_binary_svms(Xnew, Y, testXnew, testY)
    elif cmd == "multiclass":
        multiclass_svm(Xnew, testXnew, Y, testY, labels)
    elif cmd == "anomdet":
        anomaly_detection(labels, Xnew, Y, testXnew, testY)
예제 #3
0
def anom_det_test(labels, X, Y, v, ntest):
    X, Y, testX, testY = select_test_set(X, Y, ntest)
    _anom_det_test(labels, X, Y, testX, testY, v)
예제 #4
0
def monb_test(X, Y, c, onevone, ntest):
    X, Y, testX, testY = select_test_set(X, Y, ntest)
    Y = map(lambda v: v*1.0, Y)
    classify(X, Y, testX, testY, onevone, c)
예제 #5
0
def multiclass_svm_test(X, Y, labels, c, ntests):
    X, Y, testX, testY = select_test_set(X, Y, ntests)
    multiclass_svm(X, Y, testX, testY, labels, c)