I am training Recurring neural net elman in R.
nn4 <- elman(norm_traindata4,trsignals,size=10,initFuncparams=iniweight,linOut=FALSE,maxit=1000, learnFunfParams=0.01,inputsTest=norm_testdata4,targetsTest=tesignals)
predicted = predict(nn4,norm_testdata4)
Everytime I run this, the predicted values are different even for the same set of input parameters like size, learnFunParams. How to get the same predicted value for same values of parameters?
Include the following line at the beginning of your code:
set.seed(1)
Neural network uses random initial values, and can converge to a local minima. Thus setting a seed, generates the same random initial values and you get the same neural network every time.
This is due to the fact that the memory of the network changes every time you use predict
.
An Elman network predicts the output based on the inputs plus the state of a set of hidden units from the previous time step. So the 'memory'of the network changes as soon as you use predict
. The second time you use predict
the 'new' memory of the network is used together with the (in you're case, the same) inputs to predict new values.
A trick to reset you're network's memory 'back in time', predict the (training) targets using the inputs from your training sample.