Example #1
0
def main():
    patterns = [
        0x61083282abedbf10, 0xcccccccc55555555, 0x1234abcdf5ba03e7,
        0x1234abcdf5ba0132, 0
    ]
    random.seed(7)
    src = bytearray()
    src32 = bytearray()
    src3 = bytearray()
    for _ in range(512):
        src += random.choice(patterns).to_bytes(8, byteorder="big")

    for i in range(1024):
        #num = (-1 - i) + 2**32
        num = 2 * i
        src32 += num.to_bytes(4, byteorder="big")

    for _ in range(1024):
        src3 += random.randint(0, 1024).to_bytes(4, byteorder="big")

    src64 = bytearray()
    for i in range(512):
        #num =  (- 1 - i) + 2**64
        num = random.randint(1, 10000000)
        src64 += num.to_bytes(8, byteorder="big")

    src = src64
    compressor = WKCompressor(word_size_bytes=4,
                              dict_size=256,
                              num_low_bits=10,
                              debug=False)

    wk_compressed = compressor.compress(src)
    wk_uncompressed = compressor.decompress(wk_compressed)

    wk_huffman_encoded = huffman.compress(wk_compressed)
    wk_huffman_decoded = huffman.decompress(wk_huffman_encoded)
    wk_huffman_uncompressed = compressor.decompress(wk_huffman_decoded)

    lz_compressed = lzma.compress(src)
    lz_uncompressed = lzma.decompress(lz_compressed)

    zlib_compressed = zlib.compress(src, 9)
    zlib_uncompressed = zlib.decompress(zlib_compressed)

    bz_compressed = bz2.compress(src)
    bz_uncompressed = bz2.decompress(bz_compressed)

    print("LRU Histogram: ",
          WKCompressor.get_lru_queue_histogram(compressor, wk_compressed))
    indices = WKCompressor.get_dict(compressor, wk_compressed)
    print(len(indices))

    print_results("WK", src, wk_compressed, wk_uncompressed)
    print_results("WK Huffman", src, wk_huffman_encoded,
                  wk_huffman_uncompressed)
    print_results("lzma", src, lz_compressed, lz_uncompressed)
    print_results("zlib", src, zlib_compressed, zlib_uncompressed)
    print_results("bzip2", src, bz_compressed, bz_uncompressed)
Example #2
0
def test_search_print_results_should_contain_latest_versions(caplog):
    """
    Test that printed search results contain the latest package versions
    """
    hits = [{
        'name': 'testlib1',
        'summary': 'Test library 1.',
        'versions': ['1.0.5', '1.0.3']
    }, {
        'name': 'testlib2',
        'summary': 'Test library 1.',
        'versions': ['2.0.1', '2.0.3']
    }]
    print_results(hits)
    log_messages = sorted([r.getMessage() for r in caplog.records()])
    assert log_messages[0].startswith('testlib1 (1.0.5)')
    assert log_messages[1].startswith('testlib2 (2.0.3)')
Example #3
0
def test_search_print_results_should_contain_latest_versions(caplog):
    """
    Test that printed search results contain the latest package versions
    """
    hits = [
        {
            'name': 'testlib1',
            'summary': 'Test library 1.',
            'versions': ['1.0.5', '1.0.3']
        },
        {
            'name': 'testlib2',
            'summary': 'Test library 1.',
            'versions': ['2.0.1', '2.0.3']
        }
    ]
    print_results(hits)
    log_messages = sorted([r.getMessage() for r in caplog.records()])
    assert log_messages[0].startswith('testlib1 (1.0.5)')
    assert log_messages[1].startswith('testlib2 (2.0.3)')
Example #4
0
def test_diffrent_classifiers_on_aras(data_source):
    '''
    Parameters:
    if data_source = 1, it means load data from aras
    if data_source = 2, it means load data from sequential aras (first repeat of sensor is considered)
    if data_source = 3, it means load data from sequential aras (last repeat of sensor is considered)
    if data_source = 4, it means load data from sequential aras (just occurness of sensor events is considered)
    if data_source = 5, it means load data from sequential aras (number of occurness of sensor events is considered)


    '''
    names = [
        "1-Nearest Neighbors",
        "2-Nearest Neighbors",
        "3-Nearest Neighbors",
        "4-Nearest Neighbors",
        "5-Nearest Neighbors",
        #"Linear SVM",
        #"RBF SVM",
        #"Poly SVM degree = 3",
        #"Poly SVM degree = 4",
        #"Poly SVM degree = 5",
        #"LinearSVC",
        #"Gaussian Process",
        "Decision Tree",
        "Random Forest",
        "Neural Net",
        "AdaBoost",
        "Naive Bayes",
        "QDA"
    ]

    classifiers = [
        KNeighborsClassifier(1),
        KNeighborsClassifier(2),
        KNeighborsClassifier(3),
        KNeighborsClassifier(4),
        KNeighborsClassifier(5),
        #SVC(kernel="linear", C=1.0),
        #SVC(kernel='rbf', gamma=0.7, C=1.0),
        #SVC(kernel='poly', degree=3, C=1.0),
        #SVC(kernel='poly', degree=4, C=1.0),
        #SVC(kernel='poly', degree=5, C=1.0),
        #LinearSVC(C=1.0),
        #GaussianProcessClassifier(1.0 * RBF(1.0), warm_start=True),
        DecisionTreeClassifier(max_depth=5),
        RandomForestClassifier(max_depth=5, n_estimators=10, max_features=1),
        MLPClassifier(alpha=1),
        AdaBoostClassifier(),
        GaussianNB(),
        QuadraticDiscriminantAnalysis()
    ]

    if data_source == 1:
        aras = Aras.load_aras(3, isPerson=True)
    elif data_source == 2:
        aras = aras_sequentional.load_sequential_aras_first(isPerson=True)
    elif data_source == 3:
        aras = aras_sequentional.load_sequential_aras_last(isPerson=True)
    elif data_source == 4:
        aras = aras_sequentional.load_sequential_aras_occur(isPerson=True)
    elif data_source == 5:
        aras = aras_sequentional.load_sequential_aras_frequency_occur(
            isPerson=True)

    data = aras.data
    target = aras.target
    #print(len(target))
    #for i in range(len(target)):
    #   print(target[i])

    # iterate over classifiers
    for name, clf in zip(names, classifiers):
        #for i in range (3 , 4):# i indicates number of days start from Day 1
        #print("\n\n***************************************************")
        #print("number of days: " + str(i))
        #print("***************************************************")
        scores = cross_val_score(
            clf, data, target, cv=10,
            scoring='f1_macro')  ####10-fold cross validation
        print_results(name, 3, scores.mean())