0

how can I create a RL agent that has to perform on ex 1000 different episodes of 200 time steps each? Using gym-anytrading and stable-baselines3

2 Answers2

1

Something like this? You could also encapsulate your maximum steps number into your done flag within the environment's step method.

 # define your env and model above
 episodes = 1000
 for ep in range(1, episodes+1):
    state = env.reset()
    done = False
    score = 0
    step = 0

    while step < 200 and not done:
        action = model.predict(state)
        state, reward, done, _ = env.step(action)
        score += reward
        step += 1
    print (f"Episode {ep} is finished at {step} step with a score {score}")
gehirndienst
  • 424
  • 2
  • 13
1

While i can not provide exact code example since i can't see your code i can tell you approach i took on my project. You can check after a step execution if its terminal state meaning if an agent reach the goal and you can count steps and check if its above your threshold. How i did that in my code was:

while episode_counter < training_episode:
#initate your agents here
            while not (agent.is_terminal() or otherAgent.is_terminal() or anotherAgent.is_terminal()):
            #  agent execute step

Hope This would help. My code was with multiple agent but you can use same approach for single agent environments.

Aldarion
  • 26
  • 2