Tuesday, October 7, 2014

Some source code for the previous post

This is the RNN and the data sets from the previous post about the RNN target data fitting.




Fitting Pybrain's RNN prediction

After fiddling with some parameters in my original pybrain RNN, (such as the number of neurons, the training data set size and the normalization factor for the target data set) I've been able to produce RNN predictions which fit the shape of the target set, but not it's amplitude, or horizontal and vertical positions.

The following picture illustrates this problem. The blue signal is the RNN target set. The green signal is the raw RNN output for the training set input. The red signal is a crude attempt at fitting the green signal to the blue signal. It's merely a vertical displacement, together with an increase in amplitude, of the raw green signal.

Notice also how the red signal seems to be shifted to the right of the blue one. The following picture shows the prediction for 25 days after the last date in the training set. It has the same amplitude and vertical shifts as the previous picture, but I've added a left-wise horizontal shift of two days to this one.

I think I could get the red and blue signals pretty close with a simulated annealing algorithm which finds the best horizontal, vertical and amplitude shifts for the original raw green signal. I would have to use only the training set information for this, in order to make it useful for real-life prediction.

I think I'm getting pretty close to something useful here. I'll be posting some source code later.