The Task

The perceptron is a fundamental building block of a neural network. So let's play with it before moving on to multiple layer neural networks.

Build a perceptron network in C/C++ (single layer as we saw in class). It should solve a problem that consists of n inputs and m outputs. Your program will be called nn. You may use the following code but all the rest needs to be written by you (do not copy code!!): mat.tar, mat.zip These are matrix and random number routines discussed in class.

The Training

Your program will read in training data from standard input. You should then scale your input to be between 0 and 1. Your program can then train as much as you believe is needed and then print the W matrix. It will then read in test data. For this assignment use all the training data and then use the test data. Do not train on the test data. We will deal with cross validation later. The input file looks like:

#inputs
#rows #cols 
row1
row2
 ...
lastrow
#rows #cols 
row1
row2
 ...
lastrow
The training and test data each look just like a matrix specification that can be read using the provided matrix library read function. First number is the number of features or inputs. All elements in a row after the first #inputs elements are the expected outputs in the training data. The #rows in the training matrix is greater than #inputs. The #rows in the second matrix is the same as #inputs. Your program will read in the training data and then train. Your network is a single layer perceptron network with a transfer function 1.0/(1.0 + exp(- slope * x)) where slope is a parameter that you pick. Then it will read in the test data and use the trained network on the test data to derive the correct outputs.

This is some example input will test the two input logical or:

2
4 3
0 0 0
0 1 1
1 0 1
1 1 1
4 2
0 0
0 1
1 0
1 1
(The test data testDataA1.tar shows more examples of the input format.)

Then your program will print "BEGIN TESTING". After that for each test case it will print out on one line the unscaled input test case followed output using your learned W matrix. There are some single line printing routines in the matrix library that you might find helpful... or not. Please try to match the output format exactly. For instance if I print 1.00 you should not print 1. Using the mat library should get you the right output format.

You may use my random number generator and matrix objects or write your own. If you do, then be sure to include the matrix library and any other code you need to build in your tar file! Do not use any other prepackaged software. Again, please try to match my output format.

Your code must compile and run on the test machine (a Linux machine). If it does not compile or fails to run (e.g. gets seg faults) or in other ways produces no output that is a very serious fault and will result in a very poor score. In 4xx/5xx CS classes your code should at least run and produce reasonable output.

Grading will be based on matching my output. Since these programs are stochastic, I will look that the format of your output matches and the values seem reasonable. Test suite will do a side by side comparison using the standard UNIX sdiff tool. See information on the class page about testing.

Submission

Tar up all the code necessary along with a makefile to build the program named nn that reads the sample data from stdin as described above. Homework should be submitted as uncompressed tar file to the homework submission page linked from the class web page. You can submit as many times as you like. The LAST file you submit BEFORE the deadline will be the one graded. For all submissions you will receive email at your uidaho.edu mail address giving you some automated feedback on the unpacking and compiling and running of code and possibly some other things that can be autotested.

Have fun.