2
$\begingroup$

All, I am attempting to replicate the work done using Long Short Term Momory Artificial Neural Networks proposed in this thesis by following this (great) example. I have a given dataset for which I train the neural network (an interpolating function x[t] output from NDSolve):

datagraph

I train:

* Create a Neural Network and correctly format the training data to \
predict the above time series *)

inputdata = Flatten@Table[Evaluate[x[t] /. s], {t, 200, 5500}];
trainingdata = 
  RandomSample[
   List /@ Most[#] -> List@Last[#] & /@ (Partition[inputdata, 51, 1])];
LSTMANN = 
 NetChain[{LongShortTermMemoryLayer[25], LinearLayer[1]}, 
  "Input" -> {50, 1}, "Output" -> 1]

trainedLSTMANN = NetTrain[LSTMANN, trainingdata]

Then I attempt to feed the data into the neural network. I want to give it 50 samples and have the ANN output one sample (the next predicted sample in time). I have been doing the following:

ListPlot[{Flatten@Table[Evaluate[x[t] /. s], {t, 200, 550}], 
  Flatten@NestList[Append[Rest[#], trainedLSTMANN[#]] &, 
     Table[Evaluate[x[t] /. s], {t, 0, 49}], 350][[All, -1]]}, 
 Joined -> True, PlotLegends -> {"True Values", "Predicted Values"}]

But I think I know this is wrong. This is me sending the initial values of x[t] into the ANN input and the output is the same each time, no? And I repeat is 350 times? I want to send a number of samples into the ANN, output the predicted value, then repeat but in a windowed fashion where the next number of samples is time shifted. I am not extremely proficient in Mathematica and have been unable to fully understand the syntax here (what does [[All, -1]] contribute? I know that it is indexing a vector but am confused at the purpose).

Any help is appreciated!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.