예제 #1
0
def main():
    if len(sys.argv) != 3:
        print "Usage:", sys.argv[0], "<train_data_file> <test_data_file>"
        exit(1)
    train_data_file = sys.argv[1]
    verify_file_exists(train_data_file)
    test_data_file = sys.argv[2]
    verify_file_exists(test_data_file)
    train_data_list = read_data_file(train_data_file, lambda x: int(x))
    mean = float(sum(train_data_list)) / len(train_data_list)
    test_data_list = read_data_file(test_data_file, lambda x: int(x))
    max_elem = max_pois_elem(mean)
    print '\n'.join(map(lambda elem: str(log_principal_anomaly(elem, mean, max_elem)), test_data_list))
예제 #2
0
def main():
    if len(sys.argv) != 3:
        print "Usage:", sys.argv[0], "<train_data_file> <test_data_file>"
        exit(1)
    train_data_file = sys.argv[1]
    verify_file_exists(train_data_file)
    test_data_file = sys.argv[2]
    verify_file_exists(test_data_file)
    train_data_list = read_data_file(train_data_file, lambda x: float(x))
    N = len(train_data_list)
    Q = reduce(lambda acc, x: acc + pow(x, 2), train_data_list)
    S = sum(train_data_list)
    test_data_list = read_data_file(test_data_file, lambda x: float(x))
    print '\n'.join(map(lambda elem: str(log_principal_anomaly(elem, N, Q, S)), test_data_list))