Пример #1
0
def main():
    argv = sys.argv

    if len(argv) != 3:
        print('Usage: ' + argv[0] + ' model_name dataset')
        sys.exit(0)

    model_name = argv[1]
    data = datautils.load(argv[2])

    normalized, mean, std = datautils.normalize(data)
    normalized, _ = datautils.differentiate(normalized)
    (train, test) = datautils.split(normalized, 0.7)

    # utils.plot_data(data)

    print("training set length: {}".format(len(train)))
    print("test set length: {}".format(len(test)))
    """train"""
    model = LSTM()
    time_steps = 20  # window size
    batch_size = 5  # data augmentation
    history = model.train(model_name, train, 130, batch_size, time_steps)
    utils.plot_history(history)
    """test"""
    head = int(len(test) * 0.6)
    tail = len(test) - head
    projection = model.evaluate(model_name, test[:head], tail)
    """plot"""
    test = datautils.undifferentiate(test, sum(train))
    projection = datautils.undifferentiate(projection, sum(train) + sum(test))
    testset_denorm = datautils.denormalize(test, mean, std)
    results_denorm = datautils.denormalize(projection, mean, std)
    utils.plot_multiple([testset_denorm, results_denorm], [0, head + 1])
Пример #2
0
def main():
    argv = sys.argv

    if len(argv) != 4:
        print('Usage: ' + argv[0] + ' model_name dataset original_dataset')
        sys.exit(0)

    model_name = argv[1]
    data = datautils.load(argv[2])
    original_data = datautils.load(argv[3])
    normalized, mean, std = datautils.normalize(data)

    (eval_sequences, cuts_indexes) = split_evaluation_sequences(normalized)
    """eval"""
    model = LSTM()

    clean = np.empty(0)
    for head, tail in eval_sequences:
        if len(clean) == 0:
            y_init = 0
        else:
            y_init = clean[-1]
        head_diff = datautils.differentiate(head, y_init)

        projection = model.evaluate(model_name, head_diff, tail)

        head = datautils.undifferentiate(head_diff, y_init)
        projection = datautils.undifferentiate(projection, head[-1])

        clean = np.concatenate((clean, head, projection))
    """plot"""
    clean_denorm = datautils.denormalize(clean, mean, std)
    utils.plot_multiple([original_data, clean_denorm], [0, 0],
                        vertical_lines=cuts_indexes)
Пример #3
0
def main():
    argv = sys.argv

    if len(argv) != 4:
        print('Usage: ' + argv[0] + ' model_name dataset projection_length')
        sys.exit(0)

    model_name = argv[1]
    data = datautils.load(argv[2])
    tail = int(argv[3])
    normalized, mean, std = datautils.normalize(data)
    diff = datautils.differentiate(normalized)
    """eval"""
    model = LSTM()
    projection = model.evaluate(model_name, diff, tail)
    """plot"""
    results_undiff = datautils.undifferentiate(projection, normalized[-1])
    results_denorm = datautils.denormalize(results_undiff, mean, std)
    utils.plot_multiple([data, results_denorm], [0, len(data)])