Python Forum
Sequential Decision Making
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sequential Decision Making
#1
I am generating a sequential decision making model. I am using tensorflow.keras.sequantial.
But any time I train my model, I have the following error

Error:
assert_input_compatibility str(tuple(shape))) ValueError: Input 0 of layer sequential is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: (None, 30)
Here is the part of the code creating the problem,

import gym
import numpy as np
import gym_anytrading
from gym_anytrading.datasets import FOREX_EURUSD_1H_ASK, STOCKS_GOOGL
import tensorflow as tf
from tensorflow.keras import layers
import pandas as pd
import matplotlib.pyplot as plt


class QuantitativeTrading():
    def __init__(self, market):
        self.market = str(market)


    def Environment(self):
    # Set up the environment
        env = gym.make(self.market)
        return env

if __name__ == '__main__':

    # Call market
    market = 'stocks-v0'

    # Call the trader
    trader = QuantitativeTrading(market)

    # Define the model
    env = trader.Environment()
    units = env.action_space.n
    model = tf.keras.Sequential()
    model.add(tf.keras.layers.LSTM(128, input_shape=(2, env.observation_space.shape[0])))
    model.add(tf.keras.layers.Dense(units, activation='softmax'))
    model.compile(optimizer='adam', loss="mean_squared_error")

    # [layers.Dense(2, activation="relu", name="layer1"),
    #     layers.Dense(3, activation="relu", name="layer2")]

    # Train the model
    def ModelTraining(num_epochs, env, model):

        for epoch in range(num_epochs):
            state = env.reset()
            action = model.predict(state.transpose())
            next_state, reward, done, _ = env.step(action)
            model.fit(state, reward, epochs=num_epochs, verbose=0)
            state = next_state

        return action, state


    num_epochs = 100
    action, state = ModelTraining(num_epochs, env, model)
Reply


Messages In This Thread
Sequential Decision Making - by erdemath - Feb-09-2023, 09:20 PM
RE: Sequential Decision Making - by Larz60+ - Feb-10-2023, 01:20 AM
RE: Sequential Decision Making - by erdemath - Feb-10-2023, 06:30 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  sequential sampling from an array to a matrix nsansen 1 2,048 Mar-29-2020, 08:15 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020