Exemplo n.º 1
0
def main():
    configs = json.load(open('config.json', 'r'))
    if not os.path.exists(configs['model']['save_dir']):
        os.makedirs(configs['model']['save_dir'])

    data = DataLoader(os.path.join('data', configs['data']['filename']),
                      configs['data']['train_test_split'],
                      configs['data']['columns'])

    model = Model()
    model.build_model(configs)
    x, y = data.get_train_data(seq_len=configs['data']['sequence_length'],
                               normalise=configs['data']['normalise'])
    '''
	# in-memory training
	model.train(
		x,
		y,
		epochs = configs['training']['epochs'],
		batch_size = configs['training']['batch_size'],
		save_dir = configs['model']['save_dir']
	)
	'''
    # out-of memory generative training
    steps_per_epoch = math.ceil(
        (data.len_train - configs['data']['sequence_length']) /
        configs['training']['batch_size'])
    model.train_generator(data_gen=data.generate_train_batch(
        seq_len=configs['data']['sequence_length'],
        batch_size=configs['training']['batch_size'],
        normalise=configs['data']['normalise']),
                          epochs=configs['training']['epochs'],
                          batch_size=configs['training']['batch_size'],
                          steps_per_epoch=steps_per_epoch,
                          save_dir=configs['model']['save_dir'])

    x_test, y_test = data.get_test_data(
        seq_len=configs['data']['sequence_length'],
        normalise=configs['data']['normalise'])

    #predictions = model.predict_sequences_multiple(x_test, configs['data']['sequence_length'], configs['data']['sequence_length'])
    # predictions = model.predict_sequence_full(x_test, configs['data']['sequence_length'])
    predictions = model.predict_point_by_point(x_test)

    player = Player("Himanshu", 10000, 50, predictions, y_test)
    player.bet()

    #plot_results_multiple(predictions, y_test, configs['data']['sequence_length'])
    plot_results(predictions, y_test)
Exemplo n.º 2
0
class TestPlayer(unittest.TestCase):

    def setUp(self):
        self.player = Player('Rafael', 2000.0)
        self.card_one = Card('Q', 'spades')
        self.card_two = Card('A', 'spades')

    def test_repr(self):
        expected = ("Player(name='Rafael', money=Decimal('2000'), "
                    "hand=Hand(cards=[]))")
        self.assertEqual(repr(self.player), expected)

    def test_points(self):
        self.player.hand.append(self.card_one)
        self.assertEqual(self.player.points, 10)

    def test_one_card_on_hand_append(self):
        self.player.hand.append(self.card_one)
        self.assertEqual(str(self.player.hand), "1 card: Q spades")

    def test_two_cards_on_hand_append(self):
        self.player.hand.append(self.card_one)
        self.player.hand.append(self.card_two)
        self.assertEqual(str(self.player.hand), "2 cards: Q spades,A spades")

    def test_show_money(self):
        self.assertEqual(str(self.player.money), "2000")

    def test_bet(self):
        coin = self.player.bet(100)
        self.assertEqual(self.player.money, 1900.0)
        self.assertEqual(coin, 100)

    def test_bet_invalid_coin(self):
        with self.assertRaises(ValueError):
            self.player.bet(200)

    def test_len_hand(self):
        self.player.hand.append(self.card_one)
        self.player.hand.append(self.card_one)
        self.assertEqual(len(self.player.hand), 2)
Exemplo n.º 3
0
class TestPlayer(unittest.TestCase):
    def setUp(self):
        self.player = Player('Rafael', 2000.0)
        self.card_one = Card('Q', 'spades')
        self.card_two = Card('A', 'spades')

    def test_repr(self):
        expected = ("Player(name='Rafael', money=Decimal('2000'), "
                    "hand=Hand(cards=[]))")
        self.assertEqual(repr(self.player), expected)

    def test_points(self):
        self.player.hand.append(self.card_one)
        self.assertEqual(self.player.points, 10)

    def test_one_card_on_hand_append(self):
        self.player.hand.append(self.card_one)
        self.assertEqual(str(self.player.hand), "1 card: Q spades")

    def test_two_cards_on_hand_append(self):
        self.player.hand.append(self.card_one)
        self.player.hand.append(self.card_two)
        self.assertEqual(str(self.player.hand), "2 cards: Q spades,A spades")

    def test_show_money(self):
        self.assertEqual(str(self.player.money), "2000")

    def test_bet(self):
        coin = self.player.bet(100)
        self.assertEqual(self.player.money, 1900.0)
        self.assertEqual(coin, 100)

    def test_bet_invalid_coin(self):
        with self.assertRaises(ValueError):
            self.player.bet(200)

    def test_len_hand(self):
        self.player.hand.append(self.card_one)
        self.player.hand.append(self.card_one)
        self.assertEqual(len(self.player.hand), 2)