This model show an example of a Feed-forward NeuralNetwork created with the Neural Network library. This is composed by two layer: the hidden one uses a TanSig activation function and the output one uses a PureLin activation function.
This example is made using the following MatLab commands:
- clear
- t=0:0.01:10;
- x=sin(2*pi*t);
- y=cos(5*pi*t);
- for k=3:length(t) f(k)=(3*x(k)*x(k-1)*x(k-2))+(y(k)*y(k-2)); end
- var_X = [[min(x) max(x)];[min(x) max(x)];[min(x) max(x)]];
- var_Y = [[min(y) max(y)];[min(y) max(y)];[min(y) max(y)]];
- in_X = [x ; [ 0 x(1:end-1)] ; [ 0 0 x(1:end-2)]];
- in_Y = [y ; [ 0 y(1:end-1)] ; [ 0 0 y(1:end-2)]];
- net = newff([var_X ; var_Y],[4 1],{'tansig','purelin'});
- net.trainFcn = 'trainlm';
- net.trainParam.epochs = 100;
- [net,tr] = train(net , [in_X ; in_Y] , f);
- f_SIM = sim(net,[in_X;in_Y]);
- figure;
- hold;
- plot(t,f);
- plot(t,f_SIM,'r');
- IN_x=[t' , x'];
- IN_y=[t' , y'];
- OUT_f=[t' , f_SIM'];
- save testData_FeedForwardNN.mat -V4 IN_x IN_y OUT_f
- EXTRACTDATA('LW.txt','OutputLayer',net.LW{2,1},net.b{2},'lin')
- EXTRACTDATA('IW.txt','HiddenLayer',net.IW{1},net.b{1},'tan')
These commands create and train a new FeedForward Neural Network (net), which takes in input x and y and them delayed. 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 6 input (size of net.IW{1});
- The first layer of the network, the TanSig one, is made by 4 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 4 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 the extractData.m MatLab script, located in Utilities folder.
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-04-24T18:15:52Z
by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos