Esempio n. 1
0
def run_evaluation(generator, players, expected):
    '''
    Returns the accuracy of the predition.
    '''
    print 'Running experiment for %s' % expected
    outcomes = []
    for i in range(N_EVALUATIONS):
        print 'Episode %d' % i
        results = play_series(
            game=generator(),
            players=players,
            n_matches=N_MATCHES_PER_EVALUATION,
            verbose=False
        )
        outcomes.append(results[expected] / float(N_MATCHES_PER_EVALUATION))
    return np.mean(outcomes)
from capstone.game.games import TicTacToe
from capstone.game.players import KerasPlayer, RandPlayer
from capstone.game.utils import play_series

players = [KerasPlayer('models/qltic.h5'), RandPlayer()]
game = TicTacToe()
play_series(game, players, n_matches=1000)
from capstone.game.games import TicTacToe
from capstone.game.players import RandPlayer
from capstone.game.utils import play_series

game = TicTacToe()
players = [RandPlayer(), RandPlayer()]
play_series(game, players)
from capstone.game.games import TicTacToe
from capstone.game.players import MonteCarlo, RandPlayer
from capstone.game.utils import play_series

game = TicTacToe()
players = [MonteCarlo(), RandPlayer()]
n_matches = 10
play_series(game, players, n_matches)
print('')
players.reverse()
play_series(game, players, n_matches)
# result = model.predict(np.array([xx]), batch_size=1)
# print('result', result)
# import pdb; pdb.set_trace()

# history = model.fit(X_train, Y_train, batch_size=batchSize, nb_epoch=epochs, verbose=1, validation_data=(X_test, Y_test), callbacks=[])

# # Report results
# score = model.evaluate(X_test, Y_test, verbose=0)
# print 'Test score:', score[0]
# print 'Test accuracy:', score[1]

from capstone.rl.value_functions import MLP
from capstone.game.players import GreedyQ, RandPlayer
from capstone.game.utils import play_series
from capstone.game.games import Connect4
mlp = MLP()
mlp.model = model
n_matches = 1000

results = play_series(
    # game=get_random_game,
    game=C4(),
    players=[GreedyQ(mlp), RandPlayer()],
    # players=[RandPlayer(), RandPlayer()],
    n_matches=n_matches,
    verbose=True)

print('Win:', results['W'] / float(n_matches))
print('Draw:', results['D'] / float(n_matches))
print('Loss:', results['L'] / float(n_matches))
from keras.models import load_model
from capstone.game.games import Connect4
from capstone.game.players import AlphaBeta, GreedyQ, KerasPlayer, RandPlayer
from capstone.game.players.kerasplayer import KerasStatePlayer
from capstone.game.utils import play_match, play_series
from capstone.rl.value_functions import QNetwork

results = play_series(
    game=Connect4(),
    # players=[KerasStatePlayer('models/episode-14500-winpct-0.942'), RandPlayer()],
    players=[
        RandPlayer(),
        KerasStatePlayer('models/episode-14500-winpct-0.942')
    ],
    # players=[RandPlayer(), RandPlayer()],
    n_matches=100,
    verbose=True)