AI4Finance-Foundation / FinRL

FinRL: Financial Reinforcement Learning. 🔥
https://ai4finance.org
MIT License
10.06k stars 2.42k forks source link

Please help! AssertionError : assert state.shape == (args.state_dim,) #1226

Open zhipentian opened 6 months ago

zhipentian commented 6 months ago

Follow the tutorial https://github.com/AI4Finance-Foundation/FinRL-Tutorials/blob/master/3-Practical/FinRL_MultiCrypto_Trading.ipynb . Always in: Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1\plugins\python-ce\helpers\pydev\pydevd.py", line 1535, in _exec pydev_imports.execfile(file, globals, locals) # execute the script ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\JetBrains\PyCharm Community Edition 2024.1\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "D:\per\AI\test2\Crypto.py", line 44, in train(start_date=TRAIN_START_DATE, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\per\AI\test2\traintest.py", line 72, in train trained_model = agent.train_model( ^^^^^^^^^^^^^^^^^^ File "D:\per\AI\test2\elegantrl_models.py", line 107, in train_model train_agent(model) File "C:\Users\zhipe\AppData\Local\Programs\Python\Python311\Lib\elegantrl\train\run.py", line 35, in train_agent assert state.shape == (args.state_dim,) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError

Faisalsouz commented 5 months ago

same for me. please write back if you get answer: it look like that dimension model state is not matching with ENV state dimension

Derek-yfqiu commented 5 months ago

same for me... it is an urgent issue to resolve

DerekChu-YF commented 5 months ago

Problem found: in FinRL_MultiCrypto_Trading.ipynb :
model = agent.get_model(model_name, model_kwargs = erl_params) it calles FinRL-Meta/agents/elegantrl_models.py:DRLAgent:get_model. This line set by default to the StockEnv self.state_dim = 1 + 2 + 3 * stock_dim + self.tech_array.shape[1] I change it to self.state_dim = 1 + (self.price_array.shape[1] + self.tech_array.shape[1])#*lookback and it works temporary. I am able to train the model now

zhipentian commented 5 months ago

Problem found: in FinRL_MultiCrypto_Trading.ipynb : model = agent.get_model(model_name, model_kwargs = erl_params) it calles FinRL-Meta/agents/elegantrl_models.py:DRLAgent:get_model. This line set by default to the StockEnv self.state_dim = 1 + 2 + 3 * stock_dim + self.tech_array.shape[1] I change it to self.state_dim = 1 + (self.price_array.shape[1] + self.tech_array.shape[1])#*lookback and it works temporary. I am able to train the model now

Thank you very much for your help. It seems that the problem has been solved. Thank you again!

turboLIU commented 4 months ago

what is this code mean? 'self.state_dim = 1 + 2 + 3 * stock_dim + self.tech_array.shape[1]' 1 mean: ? 2 mean: ? 3 mean: ?