예제 #1
0
import gym
from agent import QAgent

env = gym.make('CartPole-v0')

agent = QAgent(env)
agent.train()
t = agent.run()
print("Time", t)
예제 #2
0
    #create env
    env = gym.make(ENV_NAME)
    print(env.unwrapped.spec.id)
    #create agent
    model = QTable(nostates=env.observation_space.n,
                   noactions=env.action_space.n,
                   learning_rate=LEARNING_RATE,
                   discount_factor=DISCOUNT_FACTOR)
    agent = QAgent(actions=env.action_space.n,
                   expl_max=EXPLORATION_MAX,
                   expl_min=EXPLORATION_MIN,
                   expl_decay=EXPLORATION_DECAY,
                   model=model)

    #get and parse user args
    args = Parser.parseargs(defaultTrainIterations=10000,
                            defaultEvalIterations=10)
    if args.load:
        agent.load(env, args.loadversion)
    if args.train != 0:
        agent.train(env,
                    iterations=args.train,
                    train_s=1,
                    save_i=SAVE_MODEL_EVERY)
    if args.eval != 0:
        print("Evaluation results (lower scores are better):")
        agent.evaluate(env, args.eval)
    if args.save:
        agent.save(env, args.saveversion)
    #close env
    env.close()