Hello everyone in this video tutorial
we are going to discuss about script for
creating time series neural network
so i have already written the code
lets look in the brief overview of this code
so first we are importing the data set
this is inbuilt data set available in matlab
in this we have the number of patient
diagnosis with chicken pox each time set represents the number of month
after that we are plotting the data
we are converting the data in the form of cell
then we are creating open loop network
there are 3 types of time series network
open loop closed loop time delay network
in open loop network we are supplying the actual input
and target to the neural network
represent the next time step value of the target series
this is the case of non linear auto regressive model
we only have the target series available
and no input series is there so in case of open loop
non linear auto regressive model we are supplying the
actual target series to predict the next future value
and in the second case that is close loop network predicted output
is used as the input to the neural network
for predicting the future time set of the time series
then we have the time delay
in this case we can predict one time step ahead prediction
of the current time step
so lets say we have currently time t
and we want to predict the outcome of the future value
at time t+1 so we can do this with the help of time delay series
in this we remove one delay
from the feedback from input
so lets run this code so after the network is trained
training window will look like this
let look at the
as we can see values are near to 90%
lets see
we can improve it by looking into the error correlation plot
as we can see the auto correlation between the error
is consider
after that we can see that these values
lie between the confidence value
so lets change the lag value
after retraining the network
we obtain the regression value
 
also error auto correlation plot shows
this lag is suitable for
so lets look into the code little bit dipper
these lines are already discussed
i have converted matrices into cell
then i have selected the training function as
and this is the feedback play i already discussed
number of hidden layers as 1
and number of neurons in it as 10
 
non linear auto regressive time series network
in this i supplied the feedback
and the training function open means
i am keeping the network as open
so i need to prepare this network so that
it can be trained for that i have given the feedback delays
this should be transferred into the
input data we have so prepare
prepared time series is the inbuilt matlab command
so i provide the network
as there are no input so this is the empty cell
t is the target x is the new input
t is the new target
xi represents the input delay state
 
lets look into these values
these are the 5 variables that i have opened
so these are out target series
as you can see there are 498 values
i have provided a delay of 12 so 498-12
that is 486 values in the
input series as this is the open series
so there will be no feedback delays
that's why it is an empty cell
and remaining 12 values that we have seen
will be stored in xi
and this is called input delay state and this is the
target series as you can see target and the input
series are the same this is the property of
non linear auto regressive time series
we have predicting the future value at that time step
that's why these 2 contains the same value
next i have provided the divide function
as divide indices you can also provide
so these 2 divide function should be used
in case of time series network
let us keep a divide note as time
now i provide a divide indices so these are the indices
that i am providing data set inputs
i kept the performance function as the mean square error
and finally i trained the network providing in
the input x
target t
input delay xi
and the feedback delay state ai
then we calculate the output of the network
by supplying the net value of x
input delay state and feedback delay state
in this i multiply the train target
the training value validation value and test value
respective mask
so this helps in removing the bad values from the data
and then finally
i calculate the performance with respect to
each of these initial
this was the open loop network and this look like
now we need to close the network
if we want to predict the outcome of the series from the network itself
continue supply of the output
close network
using the predictive value of the network
as the input as you can see
this is connected to the input
that will goes to the input delay of 12 and further to the hidden layer
now you can give the open loop network by
this is how you close the network by choosing the inbuilt matlab command
after this
the network is closed
you can also retrained the close loop network
if the performance of close loop network is not as per your expectation
so same prepare ts that is prepare time series
command will be used
this time we will be using network close loop
 
and supplying the target value t
obtaining the various parameter
and then obtainng the performance by comparing
output of the network and actual target value
in the command window we can see the test performance
open loop as this and close loop
the performance is this
so the performance is the means square error
and we can see close loop performance error
comparatively higher as open loop
and this would be obvious
as network be predictive value
and these predictive value contain error
this error keep on accumulated
 
so the performance of the close loop network is always less then the open loop network
some times we may require to do multi step multiplication
what we may do is
we keep on training until we have data in the open loop
after the data is finished we convert the network in close loop with
close loop command
and then get the number of future prediction we want
let's say we want 20 future prediction
so we create a empty cell
providing to the close loop network
with the parameter as this
and after this we can plot the results
this shows the plot i was discussing right now
so blue line is the open loop network
and this left line show the performance for 20 time steps
as you can see it is trying to follow the pattern
next we have step ahead prediction
as i already discussed sometime we may require to
predict the value at the time step t+1
when we only have the inputs time step t
so in that case what we do is remove the delay
and the feedback delay
so this can be obtain by using inbuilt matlab command
remove delay and providing the network
so this network step ahead prediction will be
and in similar way we prepare the network
and calculate the step ahead performance
the performance of step ahead is shown in command window
and it comparable to open loop
network so this is what for this type of neural network
will look like here we had delays
from 1 to 12 now we reduce the delay
so it is 0 to 11
so this was the case of non linear auto regressive model
if we have input time series as well as target time series
then we will be using time series model
that is non linear auto regressive with external input
in that case we will also have
input delay state you can study
those parameter just like i have discussed right now
few things to know
if close loop network is not performing good
then you need to retrain the close loop network
if we are using just random values
then you will only have correlation
but in real life situation most of the data
is related to light version of itself
be sure to check the auto correlation and find the
significant delay and get good amount of training data set
now lets us look at the model
 
type
 
this will open simulink diagram for the open loop network
 
this is similar to that data interpreting
in this case
delays are here
i have provided 12 delays
so there are 12 delay plot
what delay does is all the sample for 1 time delay
you can look more about the delay plot
in the simulink documentation
type
 
as you can see there is only target available
so in this case also there are 12 delays available
and we can see that
output
 
 
 
in this case we remove 1 delay
so as it should be
we have delays from 0 to 11
for all 3 networks same operation
occurs that we have discussed in simulink
diagram of data neural network
so that's it everyone this is it
hope you like it
please like subscribe and share
thanks for watching
