Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Changing the output of a neural network

Asked by John on 4 Feb 2012

Hi there,

I have a problem with the output of a neural network for data classification. The network has 4 target vectors.

Say for example the output (column vector) is

0.1	0	0.4	0.3
0.1	0.52	0.45	0.25
0.25	0.08	0.1	0.1
0.65	0.4	0.05	0.35

and then I round the output to get a one in each column, and get this

0	0	0	0
0	1	0	0
0	0	0	0
1	0	0	0

and then I use vec2ind(output) to return the rows that contain 1

It returns [4 2].

But columns 3 and 4 and are not classified.

How can I make it return the row with the highest probability estimate? So this example would return [4 2 2 4]

Many thanks

0 Comments

John

Products

No products are associated with this question.

1 Answer

Answer by Greg Heath on 5 Feb 2012

>> t = [ 0 0 0 0 % target

       0	1	1	0
       0	0	0	0
      1	0	0	1]

y = [ 0.1 0 0.4 0.3 % output

       0.1	 0.52	0.45	0.25
       0.25   0.08	0.1	0.1
       0.65	 0.4	0.05	0.35 ]

[ ymax class] = max(y)

t =

     0     0     0     0
     0     1     1     0
     0     0     0     0
     1     0     0     1

y =

    0.1000         0    0.4000    0.3000
    0.1000    0.5200    0.4500    0.2500
    0.2500    0.0800    0.1000    0.1000
    0.6500    0.4000    0.0500    0.3500

ymax =

    0.6500    0.5200    0.4500    0.3500

class =

     4     2     2     4

Hope this helps.

Greg

1 Comment

Greg Heath on 5 Feb 2012

If posterior probability estimates are desired, use the SOFTMAX activation function. However, if LOGSIG is used a reasonable approximation is to normalize the outputs to have a unity sum:

>> yn = y./repmat(sum(y),4,1)

yn =

0.0909 0 0.4000 0.3000
0.0909 0.5200 0.4500 0.2500
0.2273 0.0800 0.1000 0.1000
0.5909 0.4000 0.0500 0.3500

>> sum(yn)

ans =

1.0000 1.0000 1.0000 1.0000

Hope this helps.

Greg

Greg Heath

Contact us