AminHP / gym-mtsim

A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)
MIT License
412 stars 101 forks source link

how can I pass through the observation_space as Dict into Keras DQN model #22

Closed TanapongAUS closed 2 years ago

TanapongAUS commented 2 years ago

I have tried many time and method for this. I have writen the code below, could you please check for me whether I have done something wrong. In this case I left only this 2 informations for the experiment

model_balance = Sequential() model_balance.add(Flatten(input_shape=(1,1,1), name='balance')) model_balance_input = Input(shape=(1,1), name='balance') model_balance_encoded = model_balance(model_balance_input)

model_equity = Sequential() model_equity.add(Flatten(input_shape=(1,1,1), name='equity')) model_equity_input = Input(shape=(1,1), name='equity') model_equity_encoded = model_Equity(model_equity_input)

con = concatenate([model_Balance_encoded, model_Equity_encoded])

dense = Dense(1024, activation='relu')(con) dense = Dense(1024, activation='relu')(dense) output = Dense(actions, activation='softmax')(dense)

model = Model(inputs=[model_Balance_input, model_Equity_input], outputs=output)

memory = SequentialMemory(limit=2000000, window_length=1) policy = LinearAnnealedPolicy(EpsGreedyQPolicy()) dqn = DQNAgent(model=model, policy=policy, nb_actions=actions, memory=memory)

dqn.processor = MultiInputProcessor(2)

dqn.compile( optimizer = Adam(learning_rate=1e-4), metrics = ['mse'] #'accuracy', 'mae')

dqn.fit(env, nb_steps=1000, verbose=1, visualize=False,)

==================================================================== Then, this problem occured, and I could not find the error. 9966

please tell me the solution. thanks in advance

AminHP commented 2 years ago

Hi @TanapongAUS,

Can you upload a minimal example code to reproduce the problem?

TanapongAUS commented 2 years ago

I modified the code, to use it with CSV files which everything has been done. Except passing the observation space as dictionary through the DQN Keras model. I was trying to do as the following link which you can understand it easily:

https://gist.github.com/bklebel/e3bd43ce228a53d27de119c639ac61ee

But, it did not work for me.

please tell me the solution. thanks in advance

AminHP commented 2 years ago

I tried to run the code provided in your link, but it generates the same error. I don't think mtsim is the problem. Check out this comment in your link and its replies. They might help.