How to determine if the simulated result is matched?

1 view (last 30 days)
Here is my code:
inputData = rand(5, 56);
targetData = eye(56);
simInput = [a;b;c;d;e]; %%assume the value match 1 of the column in inputData
net = feedforwardnet(5);
net = train(net, inputData, targetData);
y1 = sim(net, simInput);
y2 = find(max(y1));
y2 should return a value that tell me which column it matched in inputData. However it only return 1 regardless the simInput. So am I using it right?

Accepted Answer

Greg Heath
Greg Heath on 7 Sep 2015
You have used random data. For a more reasonable example, go to the NN data library
help nndatasets
doc nndatasets
A simpler alternative is to just use the example in the patternnet classifier documentation
help patternnet
doc patternnet
Hope this helps.
Greg
PS: also lookup the functions IND2VEC and VEC2IND to transfer between target matrices and class indices.

More Answers (1)

Walter Roberson
Walter Roberson on 6 Sep 2015
You probably want
[maxy1, y2] = max(y1);
If y1 is a vector then max(y1) is going to be a scalar, and find() applied to a scalar is going to return [] if the scalar is 0 and is going to return 1 (the location of the non-zero element in the scalar) otherwise. find(max(y1)) does not mean to search y1 for its maximum and return the location in y2. Or maybe you just wanted to know what the maximum was; if so then just max() works.
  2 Comments
Vishnu Rajen
Vishnu Rajen on 6 Sep 2015
Thanks for the reply, now I am able to get the result. However, the result is not matched for most of the time, do you have any idea?
Walter Roberson
Walter Roberson on 6 Sep 2015
My idea is that having only 1 sample per class is not adequate to train a neural network.

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!