How can i put the conditional statement ( If-Then-else) on the specific elements (Rows/columns) of a matrix in Matlab Using Neural Network Tool?

How can i put the conditional statement ( If-Then-else) on the specific elements (Rows/columns) of a matrix in Matlab Using Neural Network Tool? Basically I am working on classification using neural Network tool in matlab. My out put only shows in matrix like : output =
1.2723
0.0123
0.0022
But I want the output in statement like "Class1" Or "Class2"
i.e. If the matrix is like this then output is this....
For example: I have two different matrices like: output1 =
1.2723
0.0123
0.0022
output2 =
0.2460
-0.0521
1.1062
%I want to set the ranges of the elements on behalf of some conditions like:
If The first element of the first row of matrix Output1 is >= 0.6 and <=1.5
AND
If The 2nd element of the 2nd row of matrix Output1 is >= -0.49 and <=0.49
AND
If The 3rd element of the 3rd row of matrix Output1 is >= -0.49 and <=0.49
THEN
Display = Class1
%for Matrix Output2:
I want to set the ranges of the elements on behalf of some conditions like:
If The 1st element of the 1st row of matrix Output2 is >= -0.49 and <=0.49
AND
If The 2nd element of the 2nd row of matrix Output2 is >= -0.49 and <=0.49
AND
If The 3rd element of the 3rd row of matrix Output2 is >= 0.6 and <=1.5
THEN
Display = Class2
Please anyone can send me the code/explanation. how can I set these condition using If-Then-else or any other statement?
Regards:
Safdar Hayat
+923335260136
Skype:
jugnu2008.safdar
Iqra University Islamabad, Pakistan

 Respuesta aceptada

If you have 4 classes, your target matrix columns should be columns of eye(4). The relationship between class indices 1:4 and the target matrix is
trueclassindices = vec2ind(target)
target = ind2vec(trueclassindices)
Example:
>> trueclassindices = [ 1 1 2 4 3 4 ]
>> target = full( ind2vec(trueclassindices))
target = 1 1 0 0 0 0
0 0 1 0 0 0
0 0 0 0 1 0
0 0 0 1 0 1
If
output =[ 0.5142 0.49114 0.18198 0 0.25288 0.13838
0.03653 0.1455 0.4168 0.14434 0.18459 0.066341
0.31642 0.22294 0.26658 0.38809 0.54807 0.35987
0.13285 0.14041 0.13464 0.46757 0.014469 0.43541]
then
assignedclasses = 1 1 2 4 3 4
Hope this helps.
Thank you for formally accepting my answer
PS. The unit sum output is a consistent estimate of the input-conditional posterior class probabilities (See any pattern-recognition text).
Greg

3 comentarios

Thanks for your Answer Greg But still I have facing problem.
like basically I have three classes 1,2 & 3:
I have many target sets as:
t1 = [0;0;0];
t2 = [0;0;0];
t3 = [0;0;0];
t4 = [0;0;0];
t5 = [0;0;0];
t6 = [0;0;0];
t7 = [0;0;0];
.
.
.
.
t342 = [0;0;0];
%These all belongs to class1.
And
t343 = [1;0;0];
t344 = [1;0;0];
.
.
.
.
t485 = [1;0;0];
%These all belongs to class2.
And
t486 = [0;0;1];
t487 = [0;0;1];
.
.
.
t560 = [0;0;1];
%These all belongs to class3.
Now when I train my network by giving total 560 examples and 560
targets then my network generate the output according to the
target set like:
output =
-0.0045
0.0056
0.0314
%Belongs to class1
output =
0.9779
-0.0082
0.0425
%Belongs to class2
output =
0.0078
0.0099
1.0794
%Belongs to class3
Now I want to display a message "class1" instead of matrix output .
for example if the output is resembled with
output =
-0.0045
0.0056
0.0314
Then Display “Class1”
Means If The value of 1st element of the 1st row of matrix "Output" is in rage of >= -0.49 and <=0.49
AND
If The value of 2nd element of the 2nd row of matrix "Output" is in rage of >= -0.49 and <=0.49
AND
If The value of 3rd element of the 3rd row of matrix "Output" is in rage of >= 0.6 and <=1.5
THEN
Display “ Class”
And want to repeat the same conditions for all outputs of all classes.
Basically I want to put the condition (range values) on the value of each element of output matrix and then display a “message” on behalf of those conditions.
Hope you will understand my question in detail.
Thank you for your moral support.
Regards:
Safdar Hayat
I understand your question.
My answer is to change your target to have {0,1} unit vectors, modify your code and train a new classifier.
Hope this helps.
Greg
Hi: Dear Greg Health !
Thanks for your moral support but your answer did not help me.
I have solved my problem by self hit and try.... :-p
I have used just targets matrix indices and then applied the loop simply as follow:
for output=sim(net, test)
X=output;
if ((X(1,1)>= -0.499) && (X(1,1)<= 0.5))&& ((X(2,1)>= -0.499) && (X(2,1)<= 0.5)) && ((X(3,1)>= -0.499) && (X(3,1)<= 0.5))
display('Class 1');
elseif ((X(1,1)>= 0.5) && (X(1,1)<= 1.5)) && ((X(2,1)>= -0.499) && (X(2,1)<= 0.5)) && ((X(3,1)>= -0.499) && (X(3,1)<= 0.5))
display('Class 2');
elseif ((X(1,1)>= -0.499) && (X(1,1)<= 0.5)) && ((X(2,1)>= -0.499) && (X(2,1)<= 0.5)) && ((X(3,1)>= 0.5) && (X(3,1)<= 1.5))
display('Class 3');
else
display('no math found');
end
end
% X(1,1) represent first element of first row and first column of matrix X.
%X(2,1) represent first element of 2nd row and first column of matrix X.
%X(3,1) represent first element of 3rd row and first column of matrix X.
  • _Yahoooo... !!!
Thanks alot_*

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Community Treasure Hunt

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

Start Hunting!

Translated by