wassname / rl-portfolio-management

Attempting to replicate "A Deep Reinforcement Learning Framework for the Financial Portfolio Management Problem" https://arxiv.org/abs/1706.10059 (and an openai gym environment)
544 stars 179 forks source link

AssertionError: action should be within Box(4,) but is array([ nan, nan, nan, nan]) #22

Closed urvishp80 closed 5 years ago

urvishp80 commented 5 years ago

I am trying out the environment you created using Keras and Q-learning algorithm. I am using this implementation https://github.com/keon/deep-q-learning/blob/master/dqn.py . I am encountering the following error

--------------------------------------------------------------------------- AssertionError Traceback (most recent call last)

in () 5 # env.render() 6 action = agent.act(state) ----> 7 next_state, reward, done, _ = env.step(action) 8 reward = reward if not done else -10 9 #next_state = np.reshape(next_state, [1, state_shape]) C:\Program Files (x86)\Python\New folder\lib\site-packages\gym\core.py in step(self, action) 94 info (dict): contains auxiliary diagnostic information (helpful for debugging, and sometimes learning) 95 """ ---> 96 return self._step(action) 97 98 def reset(self): E:\Pirimid\rl-portfolio-management\rl_portfolio_management\environments\portfolio.py in _step(self, action) 313 # Sanity checks 314 assert self.action_space.contains( --> 315 action), 'action should be within %r but is %r' % (self.action_space, action) 316 np.testing.assert_almost_equal( 317 np.sum(weights), 1.0, 3, err_msg='weights should sum to 1. action="%s"' % weights) AssertionError: action should be within Box(4,) but is array([ nan, nan, nan, nan])` I am not that much familiar with gym environments and deep RL.
wassname commented 5 years ago

I that means that the action your passing in is "nan", so that's likely a problem with your model. Perhaps try to trace back where the nans are coming from.

Also this repo has been forked and improved here: https://github.com/vermouth1992/drl-portfolio-management and https://github.com/awslabs/amazon-sagemaker-examples/blob/master/reinforcement_learning/rl_portfolio_management_coach_customEnv/rl_portfolio_management_coach_customEnv.ipynb

I should add those links to the readme.