I am trying to use LSTM neural network (using Keras) to predict opponent's next move in the game Rock-Paper-Scissor.
I have encode the inputs as Rock: [1 0 0], Paper: [0 1 0], Scissor: [0 0 1]. Now I want to train the neural network but I am a bit confused of the data structure of my training data.
I have stored an opponent's game history in a .csv file with the following structure:
1,0,0
0,1,0
0,1,0
0,0,1
1,0,0
0,1,0
0,1,0
0,0,1
1,0,0
0,0,1
And I am trying to use every 5th data as my training label, and the previous 4 data as the training input. In another word, at each time step, a vector with dimension 3 is sent to the network, and we have 4 time steps.
For example, the following is the input data
1,0,0
0,1,0
0,1,0
0,0,1
And the fifth one is the training label
1,0,0
My question is what type of data format does Keras' LSTM network accept? What would be an optimum way to rearrange my data for this purpose? My incomplete code is attached as following if it helps:
#usr/bin/python
from __future__ import print_function
from keras.models import Sequential
from keras.layers import Dense, Activation, Dropout
from keras.layers.recurrent import LSTM
from keras.optimizers import Adam
output_dim = 3
input_dim = 3
input_length = 4
batch_size = 20 #use all the data to train in one iteration
#each input has such strcture
#Rock: [1 0 0], Paper: [0 1 0], Scissor: [0 0 1]
#4 inputs (vectors) are sent to the LSTM net and output 1 vector as the prediction
#incomplete function
def read_data():
raw_training = np.genfromtxt('training_data.csv',delimiter=',')
print(raw_training)
def createNet(summary=False):
print("Start Initialzing Neural Network!")
model = Sequential()
model.add(LSTM(4,input_dim=input_dim,input_length=input_length,
return_sequences=True,activation='softmax'))
model.add(Dropout(0.1))
model.add(LSTM(4,
return_sequences=True,activation='softmax'))
model.add(Dropout(0.1))
model.add(Dense(3,activation='softmax'))
model.add(Dropout(0.1))
model.add(Dense(3,activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='Adam',metrics=['accuracy'])
if summary:
print(model.summary())
return model
if __name__=='__main__':
createNet(True)