if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--batch_size", type=int, default=256) parser.add_argument("--memory_limit", type=float, default=0.2) parser.add_argument("--learn_rate", type=float, default=1e-3) parser.add_argument("--eplen_bonus", type=float, default=0) # reward on the episode length parser.add_argument("--discount_rate", type=float, default=0.99) parser.add_argument("--replay_size", type=int, default=10000) parser.add_argument("--exploration", type=float, default=0.2) parser.add_argument("--save_freq", type=int, default=100) parser.add_argument("--save_folder", type=str, default="model") parser.add_argument("--reload", type=str, default=None) args = parser.parse_args() gmm = gameMgr.tetris(20, 10) gmm.setScore(drop=1, eplen_bonus=args.eplen_bonus, terminal=-1.) epoch = 0 write_epoch = 100 reward_history = collections.deque(maxlen=1000) rewardDrop_history = collections.deque(maxlen=1000) agt = agent.agent(gmm.getActionList(), gmm.getScreenSize(), gmm.getNextBlockSize(), n_batch=args.batch_size, learning_rate=args.learn_rate, discountRate=args.discount_rate, saveFreq=args.save_freq, saveFolder=args.save_folder, memoryLimit=args.memory_limit)
import numpy as np import gameMgr import dqn_agent_tetris import collections import matplotlib.pyplot as plt import csv def mean(x): return float(sum(x)) / len(x) showInterval = -1 if __name__ == "__main__": gmm = gameMgr.tetris(12, 6) epoch = 0 reward_history = collections.deque(maxlen=1000) loss_history = collections.deque(maxlen=1000) n_batch = 256 agt = dqn_agent_tetris.DQNAgent(gmm.getActionList(), "tetris", gmm.getScreenSize()[0], gmm.getScreenSize()[1]) #agt.load("model/model.ckpt") fig = plt.figure(figsize=(gmm.getScreenSize()[0], gmm.getScreenSize()[1])) fig.canvas.set_window_title("TeTris") logFile = file("log", "w") logCSV = csv.writer(logFile) logCSV.writerow([ "epoch", "last_loss", "loss_mean", "last_reward", "mean_reward", "max_reward"