multi-input multi-output regression Problem

318 views
Skip to first unread message

chen...@gmail.com

unread,
Aug 21, 2017, 9:38:34 AM8/21/17
to Keras-users
Hi everyone,

I want to build a model to describe a dynamic system. it has 3 inputs and 3 outputs, each of these signal is a time sequence (e.g. acceleration-time).
the model should be able to give the "right" outputs when given "new" inputs. one idea is to train the network base on Inputs of the past, say 20 timesteps.

so I merged my 3 inputs into a input matrix with the size of (timesteps, 3), and I set my timesteps for training as 10. So I scan through my whole input matrix with the timestep window for each iteration and train my network with it.
after the training I want to test the net with the same training data, but I got only straight lines as my output. I've however predict the output of the net along with training, means that I put predict() in the loop and it seems work fine.

here is some code of it, can someone enlighten me on this? many thx.

# I/O dimension, shape of data


batch_start= 0
time_steps= 10
input_length= 3
target_length= 3


# build model


model= Sequential()
model.add(Conv1D(64, 6, input_shape= (time_steps, input_length)))
model.add(Conv1D(32, 5))
model.add(Flatten())
model.add(Dense(64))
model.add(Dropout(0.25))
model.add(Dense(64))
model.add(Dense(32))
model.add(Dense(16))
model.add(Dense(8))
model.add(Dense(3))
model.compile(optimizer= 'rmsprop', loss= 'mean_squared_error')


# train model


for i in range(len(t)-batch_size*time_steps):
   

    t_fit= t[batch_start:batch_start+time_steps]
    input_ts_fit= input_ts[batch_start:batch_start+time_steps]                 # input matrix in timesteps window
    target_ts_fit= target_ts[batch_start+time_steps]                                # the output at t+1

  
input_ts_fit= input_ts_fit[np.newaxis,:,:] #fit the dimension of data target_ts_fit= target_ts_fit[np.newaxis,:]
batch_start += 1

# fit model model.fit(input_ts_fit, target_ts_fit, batch_size=5, epochs= 10)


# predict data based on training example


batch_start= 0


for i in range(len(t)-batch_size*time_steps):
     # data preparation as the same above
     pred_ts = model.predict(input_ts_fit)
     batch_start += 1
     # plot the result


Daπid

unread,
Aug 21, 2017, 9:45:21 AM8/21/17
to chen...@gmail.com, Keras-users
On 21 August 2017 at 15:38, <chen...@gmail.com> wrote:

model= Sequential()
model.add(Conv1D(64, 6, input_shape= (time_steps, input_length)))
model.add(Conv1D(32, 5))
model.add(Flatten())
model.add(Dense(64))
model.add(Dropout(0.25))
model.add(Dense(64))
model.add(Dense(32))
model.add(Dense(16))
model.add(Dense(8))
model.add(Dense(3))
model.compile(optimizer= 'rmsprop', loss= 'mean_squared_error')


Your model is completely linear, you don't have any activation function. Add one relu after each layer, and keep up to three dense layers, as more will not get better.


Another option is to make a fully convolutional network and predict everything at once giving everything in the past. You can achieve this stacking Conv1D layers with padding="causal", and the last one having three filters.
Reply all
Reply to author
Forward
0 new messages