This model show an example of a Recurrent NeuralNetwork created with the Neural Network library.
A Recurrent Neural Network is composed by a layer of neurons which adopts the TanSig activation function and a layer of newrons which perform a LogSig transformation.
This example is made using the following MatLab commands:
- P = round(rand(1,80));
- T = [0 (P(1:end-1)+P(2:end) == 2)];
- Pseq = con2seq(P);
- Tseq = con2seq(T);
- net = newelm([0 1],[20 1],{'tansig','logsig'});
- net.trainParam.epochs = 500;
- net = train(net,Pseq,Tseq);
- Y = sim(net,Pseq);
- z = seq2con(Y);
- figure
- plot(T)
- hold
- plot(z{1,1},'r')
- time=(1:length(P))*0.01;
- in=[time' P'];
- out=[time' z{1,1}'];
- tanL_weight=[net.LW{1} net.IW{1,1}];
- tanL_bias=net.b{1};
- logL_weight=net.LW{2,1};
- logL_bias=net.b{2};
- typing this command in matlab: save testData_RecurrentNN -V4 in out tanL_weight tanL_bias logL_weight logL_bias
These commands create and train a new Recurrent Neural Network (net). The detail about the network created can be see exploring the network object created by matlab. Which is important for our example are these informations:
- The first layer of the network, the TanSig one, expect 1 input (size of net.IW{1});
- The first layer of the network, the TanSig one, is made by 20 newrons (size of net.IW{1});
- The weight table of the first layer is net.IW{1};
- The bias table of the first layer is net.b{1};
- The second layer of the network, the LogSig one, expect 20 inputs (size of net.LW{2});
- The second layer of the network, the LogSig one, is made by 1 newron (size of net.LW{2});
- The weight table of the second layer is net.LW{2};
- The bias table of the second layer is net.b{2};
In this example the parameters of the network are specified using two different way:
- using the extractData.m MatLab script, located in Utilities folder
- extractData('dataHidden.txt','HiddenLayer',[net.LW{1},net.IW{1,1}],net.b{1},'tan',1)
- extractData('dataOutput.txt','OutputLayer',[net.LW{2,1}],net.b{2},'log')
- using the DataFiles Dymola library.
The model is simulated on the same data used in MatLab so it is possible to test if the model gives the expected output.
Release Notes:
Generated at 2024-03-27T19:15:56Z
by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos