Online Leanring with adapt function
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to use adapt function for online learning. That is in each iteration a new training sample is generated and the adapt function is called to fit the sample in the neural network.
I started with a simple problem of fitting a equation (y=2*x1+x2). In each iteration x1 and x2 are random integers between 1 to 10 are taken and the adapt function is called to fit the sample. The neural network has 2 inputs (x1,x2) and 1 output(y). The fitnet neural network is used with 2 hidden layers of size[4,4]. Please find the code below for more details.
The issue is after the online learning, the outputs of the neural network are some for different inputs. It looks like the adapt function learning doesn't consider the inputs. What changes should I make so as to get the desired outputs from the neural networks for the given inputs. I cannot use train function because its batch learning and requires all the samples together.
CODE:
%%%%
nn = fitnet([4,4]); %hiddenlayer of size [4,4]
nn.inputs{1}.size = 2; %Inout layer size 2 (x1,x2)
nn.layers{size([4,4],2)+1}.size = 1; % Output layer size 1 y
%learning rate =0.1
nn.inputWeights{1,1}.learnParam.lr = 0.1;
nn.biases{1,1}.learnParam.lr = 0.1;
nn.biases{2,1}.learnParam.lr = 0.1;
nn.biases{3,1}.learnParam.lr = 0.1;
nn=init(nn); %initialize the neural network
% 100 samples are generated one by one In each iteration adapt is called to fit the new sample
for x=1:100
x1=randi(10);
x2=randi(10);
y=2*x1+x2;
nn=adapt(nn,[x1;x2],y);
end
%Output test
disp([nn([1,1]') 3])
disp([nn([4,3]') 11])
disp([nn([7,6]') 20])
%The outputs
17.2323 3.0000
17.2459 11.0000
17.2459 20.0000
%%%%
Any help would be great. Thank you
0 Commenti
Risposta accettata
Greg Heath
il 1 Lug 2016
Read the ADAPT documentation to verify that ADAPT is meant to be used for timeseries.
help adapt
doc adapt
In other words, adjoining points must be correlated.
Therefore, your example is invalid.
To obtain MATLAB demo data for NN examples use
help nndatasets
doc nndatasets
Hope this helps.
Thank you for formally accepting my answer
Greg
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Deep Learning Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!