## Changing the output of a neural network

### John (view profile)

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

## Products

No products are associated with this question.

### Greg Heath (view profile)

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

Greg Heath

### Greg Heath (view profile)

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

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