开发者

problem in understanding the code

开发者 https://www.devze.com 2023-01-11 14:33 出处:网络
i = 0; while (fscanf(fp, \"%f %f %d开发者_开发百科\", &x[i], &y[i], &outputs[i]) != EOF) {
i = 0;
while (fscanf(fp, "%f %f %d开发者_开发百科", &x[i], &y[i], &outputs[i]) != EOF) {
    if (outputs[i] == 0) {
        outputs[i] = -1;
    }
    i++;
}
patternCount = i;

I dont understand the meaning of this line from the above code:

if (outputs[i] == 0) {
        outputs[i] = -1;

What does it represent. The Output is a matrix or vector.??

The refrence of the code is: Perceptron learning algorithm not converging to 0

I have a output file that has 3 columns:

1 0 0
0 0 1
0 1 0

So it a vector file??



outputs is defined as a one-dimensional array containing integer values..

float x[208], y[208];
int outputs[208];


Each index in the array can be seen as corresponding to a line read in the data file.

  i       x              y      outputs
  --------------------------------------
  0 | -8.818681   3.025210     1
  1 |  3.653846  -2.969188     0
  2 |  ...           ...           .
 .. |  ...           ...           .
208 | -6.565934  -4.649860     1

Where if i == 0 then

x[0]       == -8.818681
y[0]       == 3.025210
outputs[0] == 1


The wonderful code and information posted by user Amro explain the limits and function of outputs.

"...bias term, i.e. a third weight component connected to an input of value 1. (+1/-1) "


Values for outputs in the data file have been assigned one/zero values. Therefore the code in question checks to see if the value for outputs read in from the file is equal to zero and re-assigns to a -1.

if (outputs[i] == 0)
    outputs[i] = -1;


as far as I can tell, the code is reading from a file, and the file is supposed to have a repeated pattern, each pattern consists of 3 numbers.

Your loop copy the first number in each pattern to x, the second to y, and the last to outputs. However whenever the third number is a zero, it is changed to -1.

patternCount will store the number of pattern read in the file


A perceptron is a term from artificial intelligence/neural networks. It operates in much the same way as a single neuron is supposed to operate in the brain.

It has a number of inputs and a single output.

All this file is doing is specifying what the output should be for a given set of inputs. That's why the x/y and output are named differently.

As to why it's morphing the output from 0 to -1 (that's all it's doing by the way: changing zeros in the third file column into negative one), I'm not sure. The outputs of perceptrons almost invariably feed into other perceptrons so passing a -1 to something that expects 0 or 1 is an ... interesting ... idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消