basic neural network in C

profileJack Jonshen
ProjectInstruction.pdf

Assignment Instructions

For this assignment, you need to implement two functions to complete the basic neural network for handwriting recognition by deep learning:

Function 1: backPropogation( ) to compute the parameters theta and bias between layers. This function will be called during the training stage.

Function 2: numPrediction( ) to predict the number for an input handwriting image. This function will be called during the testing stage.

For both functions, you just need to focus on the implementation and don’t worry about where to call or use them as they are already done in the framework. You can find these two function definition (with empty body) at the top of the “main.cpp” file, with the following comments:

/******************** Implementation Here *******************/

Your code will be just in this region (so you only need to modify the “main.cpp” file)

/**************** End of Implementation ******************/

Please refer to the code file to see the details about how to implement the two functions.

How to run the framework

After unzip the folder, you will see four source code files “main.cpp”, “data_loading.cpp”, “header_file.h”, and “utilis.h”. You just need to put them in your project source code folder. Only the “main.cpp” is the file you will modify. So you don’t need to touch the other three files.

In addition, you notice there are three folders “models”, “test_images”, “train_images”. Initially, they are empty. But you need to keep these folders in your project default (or executable) folder, as they will be used to store the training results.

Furthermore, you need to put four training data of collected handwriting images in your project default folder: “t10k-images.idx3-ubyte”, “t10k-labels.idx1-ubyte”, “train-images.idx3- ubyte”, and “train-labels.idx1-ubyte”. These four files will be used for data training.

After finishing the above configuration, you can start run the code. There are two running modes involved: training stage mode and testing stage mode. You can switch between them by modifying the macro “MODE” at the top of the “main.cpp” (line # 6):

#define MODE 1 // 0 - training mode; 1 - testing mode

If you set it to 0, it will be run as a training procedure which will call the “backPropogation( )” function; if you set it to 1, it will run as the testing procedure which will call “numPrediction( )”. Usually, you should first set MODE to 0 first to learn the model “theta_1”,

“theta_2”, “bias_1” and “bias_2”. Then these four variables will be automatically stored as local files. When you run the code with MODE equal to 1, these variables will be loaded automatically and used for prediction.

Rubrics:

(1) Successful implement the parameter update for theta_1 and theta_2 (25%)

(2) Successful implement the parameter update for bias_1 and bias _2 (15%)

(3) Successfully use the theta_1, theta_2, bias_1, bias_2 to map the neurons between layers (50%)

(4) Successfully use activation function to compute the output for each neuron (10%)

Submission:

- The source code. You can just turn in the “main.cpp” file.

- Additional document (.docx, or .pdf) describing your experimental results. This is recommended but not requrired.