seeking advice with rounding NN output and vec2ind

1 次查看(过去 30 天)
Hi there,
I am using the following code to classify data with a neural network. I first classify the data with the network, then round the output and then convert the vector to an integer (i.e. 1,2,3).
output = sim(net, tmparray);
outputrounded = round(output);
result = vec2ind(outputrounded);
However, sometimes the NN cannot match the input to a particular target,so when the output is rounded they are all zeros, so when it is converted from a vector to an integer there is no output.
If this happens is there anyway to force the result to be a zero?
The reason I ask is because when you are classifying thousands of samples one after another and one sample cannot be classified and there is no result , it is very difficult to identify which input resulted in this.
Thank you

回答(3 个)

Walter Roberson
Walter Roberson 2012-7-15
Replace the vec2ind() with matrix multiplication.
mvec = 1 : size(outputrounded,1);
result = mvec(:) * outputrounded;

Greg Heath
Greg Heath 2012-7-15
For classification of c mutually exclusive classes, use a target matrix consisting of the columns of the c-dimensional unit matrix eye(c).
Use softmax as the output activation function. Then all outputs are in the OPEN interval (0,1) and sum to 1.
classindices = [ 4 2 3 1 2]
target = ind2vec(classindices)
target = full(target)
rng(0)
output = softmax(target+0.3*randn(4,5))
predclass = vec2ind(output)
Err = predclass~=classindices
If the classes are NOT mutually exclusive (e.g., tall,dark,handsome), use logsig as the output activation function. Then all outputs are in the OPEN interval (0,1) but do NOT sum to 1.
Outputs of exactly 0 or 1 are the results of floating point error.
rng(0)
target = round(rand(3,5))
output = logsig(target+0.4*randn(3,5))
predclasses = round(output)
Err = predclasses-target
Nerrs = sum(Err,2)
Hope this helps.
Greg
  2 个评论
Greg Heath
Greg Heath 2012-7-15
Outputs of exactly 0 or 1 are the results of floating point ROUNDOFF.
Classification thresholds:
rng(0)
target = round(rand(3,5))
output = logsig(target+0.4*randn(3,5))
thresholds = [0.4 0.5 0.6]'
predclasses = bsxfun(@ge,output,thresholds)
Err = predclasses~=target
Nerrs = sum(Err,2)
Vikas
Vikas 2016-4-15
编辑:Vikas 2016-4-15
But in the case after using softmax/logsig transfer function there is a possibility to get equal values[0.5,0.5] for two class problem or [0.25, 0.25, 0.25, 0.25] for 4 class problems, in that case what vec2ind(output) will do? it is in the document that it will go in the first class. Is it not be incorrect, if modeller change the class order? Kindly share your wisdom. so vec2ind([0.25;0.25;0]) = 1; but vec2ind([0;0.25;0.25]) = 2 if we change the order of the class output.

请先登录,再进行评论。


Greg Heath
Greg Heath 2016-4-16
There are two binary conditions (four combinations) to consider
1. Type of targets
a. Mutually exclusive targets:
{0,1} unit vector
b. Non-mutually exclusive targets:
unit sum non-negative element vector
2. Type of classification
a. Forced classification: At least
one class is always chosen
b. Conditional classification: No
class is chosen if the maximum
output is less than a specified
threshold.
YOU have to consider which combination you will use.
Hope this helps.
Greg

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by