Exemple #1
0
    def test_load_data(self):
        from build import load_data

        res = load_data()

        self.assertEqual(13, res['# Summer']['Afghanistan'])
        self.assertEqual(152, res['Silver']['Australia'])
Exemple #2
0
    def test_get_points(self):
        from build import get_points, load_data
        res = load_data()
        res = get_points(res)

        self.assertEqual(2, res['Afghanistan'])
        self.assertEqual(130, res['Argentina'])
        self.assertEqual(923, res['Australia'])
        self.assertEqual(569, res['Austria'])
        self.assertEqual(276, res['Belgium'])
def main():
    parser = OptionParser()
    opt = parser.parse_args()

    filename = opt.filename
    step = opt.step
    epochs = opt.epochs

    x_train, y_train, x_val, y_val, x_test, y_test, gt_test, max_data, min_data = load_data(
        filename, step)

    opt.max_data = max_data
    opt.min_data = min_data
    opt.train_len = x_train.shape[1]
    opt.val_len = x_val.shape[1] - x_train.shape[1]
    opt.test_len = x_test.shape[1] - x_val.shape[1]

    lstm = LSTM(1, 50, 1)
    sfm = SFM(1, 50, 20, 1)

    net = sfm
    train_function = train_sfm
    test_function = test_sfm

    if opt.net not in ["lstm", "sfm"]:
        raise NameError("Undefined net!!")

    if opt.net == "lstm":
        net = lstm
        train_function = train_lstm
        test_function = test

    print("Using net: %s" % (opt.net))

    if opt.train:
        train_function(net, x_train, y_train, epochs=epochs)
    if opt.test:
        test_function(net, x_test, y_test, opt)
                        type=str,
                        default='../dataset/data.npy')
    # visualization
    parser.add_argument('-v',
                        '--visualization',
                        type=distutils.util.strtobool,
                        default='false')
    args = parser.parse_args()
    step = args.step

    global_start_time = time.time()

    print '> Loading data... '

    data_file = args.data_file
    X_train, y_train, X_val, y_val, X_test, y_test, gt_test, max_data, min_data = build.load_data(
        data_file, step)
    test_len = X_test.shape[1] - X_val.shape[1]
    print 'test length:', test_len

    print '> Data Loaded. Compiling...'
    #dimension of hidden states
    if step == 1:
        hidden_dim = 10
    elif step == 3:
        hidden_dim = 50
    elif step == 5:
        hidden_dim = 50
    else:
        raise Exception(
            "Don't have the model pretrained with the n-step prediction.")
    #number of frequencies
Exemple #5
0
import build as b

df = b.load_data()

print(df)

print(b.first_country(df))

print(b.gold_medal(df))

print(b.biggest_difference_in_gold_medal(df))

p = b.get_points(df)
print(p)

print(b.k_means(df))
Exemple #6
0
    def test_biggest_difference_in_gold_medal(self):
        from build import biggest_difference_in_gold_medal, load_data
        res = load_data()
        res = biggest_difference_in_gold_medal(res)

        self.assertEqual('United States', res)
Exemple #7
0
    def test_gold_medal(self):
        from build import gold_medal, load_data
        res = load_data()
        res = gold_medal(res)

        self.assertEqual('United States', res)
Exemple #8
0
    def test_first_country(self):
        from build import first_country, load_data
        res = load_data()
        res = first_country(res)

        self.assertEqual(13, res["# Summer"])