Example seems to be broken
aheagel opened this issue · 4 comments
It seems that the example code at https://github.com/AminHP/gym-anytrading#a-complete-example is broken. Running the code returns: Perhaps I've missed something?
AssertionError: The observation returned by the `reset()` method is not contained with the
observation space (Box(-inf, inf, (10, 2), float32))
import gym
import gym_anytrading
from gym_anytrading.envs import TradingEnv, ForexEnv, StocksEnv, Actions, Positions
from gym_anytrading.datasets import FOREX_EURUSD_1H_ASK, STOCKS_GOOGL
import matplotlib.pyplot as plt
env = gym.make('forex-v0', frame_bound=(50, 100), window_size=10)
# env = gym.make('stocks-v0', frame_bound=(50, 100), window_size=10)
observation = env.reset()
while True:
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
# env.render()
if done:
print("info:", info)
break
plt.cla()
env.render_all()
plt.show()
After debugging for a while I found out that the reset function needs to be in float32 whereas the returned value was float64. Hence changing the observation_space from
to
self.observation_space = spaces.Box(low=-np.inf, high=np.inf, shape=self.shape, dtype=np.float64)
seems to solve the problem in my case
Hi @aheagel ,
It works for me too. Thanks for the fix. Do you want to create a pull request?
Hi @aheagel ,
It works for me too. Thanks for the fix. Do you want to create a pull request?
I'm still very new to this community and I haven't yet figured out how to use git. So i think it is better if you do it in case i mess up.
Alright. As you wish :)