AI4Finance-Foundation / FinRL

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

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

Open zhipentian opened 1 month ago

zhipentian commented 1 month 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 1 month 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 1 month ago

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

DerekChu-YF commented 1 month 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 1 month 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 2 weeks 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: ?