What is the cause of my patternnet apapt error?

I am trying to do adaptive training of a neural network using patternnet using all default settings, so the following is my complete code (except for array initialisation). The train code works, and is verified to produce accurate output :
X is [101,12507] of training data, T is [133,12507] of classification data
net = patternnet(101);
net = train(net,X,T);
If I try adaptive training with one sample :
X is [101,1] of training data, T is [133,1] of classification data
net = patternnet(101);
net = adapt(net,X,T);
I get the following error:
Error using *
Inner matrix dimensions must agree.
Error in nn7.grad2 (line 108)
gNi(:,qq) = Fdot{qq}' * gA{i}(:,qq);
Error in adaptwb>adapt_network (line 100)
[gB,gIW,gLW] =
nn7.grad2(net,[],PD(:,:,ts),BZ,IWZ,LWZ,N,Ac(:,ts+AcInd),gE,Q,1,hints);
Error in adaptwb (line 37)
[out1,out2,out3] = adapt_network(in1,in2,in3,in4);
Error in network/adapt (line 108)
[net,Ac,tr] = feval(net.adaptFcn,net,Pd,T,Ai);
Error in D_Train_Net_Adapt (line 14)
net = adapt(net,X,T);

1 commentaire

What I am attempting to do here is train a patternnet progressively as input data enters the system - the number of hidden nodes could be 10 - I have just chosen an arbitrary number. It is classifying data from a histogram of size 101 and classifying this as one of 133 known features. Data will arrive live in a stream, so I am attempting to progressively train the system and use the network when I want to query some input data with an unknown feature classification. Any ideas about the best way to do this?

Connectez-vous pour commenter.

 Réponse acceptée

Greg Heath
Greg Heath le 8 Août 2015
% You are trying to design a classifier that classifies 101-dimensional vectors into one of 133 classes. using a net with 101 hidden nodes.
% What kind of input data is that and what kind of target classes are those?
% This is such a highly unusual and unlikely scenario that I suggest you illustrate your problem with a MATLAB example dataset.
% The documentation commands "help patternnet" and "doc patternnet" both yield examples using the iris_dataset containing fifty 4 dimensional vectors from each of 3 classes
% The help and doc commands for adapt indicate it was meant for timeseries, not classification. Nevertheless, it will be interesting to see how well it does.
% Removing ending semicolons will print the results of any command
close all, clear all, clc
[ x, t] = iris_dataset;
[ I N ] = size(x) % [ 4 150 ]
[ O N ] = size(t) % [ 3 150 ]
% TCI TrueClassIndices: 1, 2 and 3
TCI = vec2ind(t);
H = 10 % default No. of hidden nodes
% NET TRAINING
net1 = patternnet(H);
rng(4151941) % my RNG initialization
[ net1 tr y1 e1 ] = train(net1,x,t);
% PCI PredictedClassIndices: 1, 2 and 3
PCI1 = vec2ind(y1);
Errors1 = [ PCI1 ~= TCI ]; % 0s and 1s
Nerrs1 = sum(Errors1) % 4
PctErr1 = 100*Nerrs1/N % 2.67
% NET ADAPTATION
net2 = patternnet(H);
rng(4151941) % my RNG initialization
[ net2 y2 e2 xf af ar] = adapt(net2,x,t);
% PCI PredictedClassIndices: 1, 2 and 3
PCI2 = vec2ind(y2);
Errors2 = [ PCI2 ~= TCI ]; % 0s and 1s
Nerrs2 = sum(Errors2) % 91
PctErr2 = 100*Nerrs2/N % 60.7
% Since the initial weights and random data divisions depend on the RNG state, many more nets have to be designed before a definitive conclusion can be made about the ability of adapt to be used for this problem.

1 commentaire

Using a double loop approach
for h = 0:5:40 % No. of hidden nodes
...
for ntrials = 1:10 % Loop over different RNG states
% to obtain different random initial weights and trn/val/tst divisions
...
end
end
None of the runs are good because the adaptation stops after only 1 epoch!
This may have to do with adapt being a timeseries function which, in general depends on input and feedback lags.
More later,
Greg

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by