Programming

profileibra-85
class5200_hw5q.docx

Homework # 5

Due Date: Tuesday, Nov 8, 2016

Purpose: The goal in this assignment is to complete the Hebb artificial neural network used for pattern recognition.  In this step we calculate the neural network output corresponding to a test data file.

Code Requirements:

-Include the problem statement in the top of the java code (copy and paste this document using comments)

-Include comments in the code

-Perform all the steps required in homeworks # 3 and # 4.

-Read the 16 test patterns from file test_data.txt. A description of this file is found in Appendix A.  Note that in some cases the data has noise but will still recognize a character.  In other cases the character is quite different from the training patterns.  After you read this data into the integer array S_new[ ][ ],make sure you convert it to bipolar using the statement below:

S_new[k][i] = 2 * S_new[k][i] - 1;

-Use the algorithm shown in Appendix B to construct the bipolar output array y[ ][ ] of type integer.

-Construct a string array y_out[ ] of size p_test+1 which contains the string representation of the output, described in Appendix C. For instance, the possible output strings can be “A”, “B”, “C”, “D”and “*”. 

-Create a file y_out.txt and store the pattern number, the output bipolar representation and the corresponding output string as described in Appendix D.  The outputs for a given pattern must be included in the same line.

List of required deliverables

-An updated flowchart or pseudocode that shows the code logic

-A java code or codes

-All the generated output files (including those from homework # 3 and #4)

-Compress all these files in a folder and post in the Canvas assignment corresponding to homework # 5.

How it will be graded:

-All the required files and documents must be provided.

-The Java code must produce the correct results.

-The assignment must be submitted on time for full credit.

-Code style: Include comments in your code, use spaces to improve code readability.

-Efficiency: Make sure your code follows the logic shown in your flowchart or pseudocode.

-The rubrics used for the grading is presented in Appendix E.

Additional notes:

Any code that is not yours must be referenced.  For instance, provide the web link, author and so forth.  

Academic integrity will be enforced as needed.  For instance, it is not acceptable students submitting identical codes, or copying code from the web without referencing them.

Appendix A.  File test_data.txt

The number of test patterns, and the number of rows and columns for each pattern are shown.  In this case only 3 test patterns are shown, but in the actual data file there are 16 patterns.  The pattern number is shown below each pattern matrix.

Appendix B.  Java code for calculating the Hebb neural net output.

// p_test is the number of test patterns

 

int y_in;

int y[][]=new int[p_test+1][m+1];

 

      // Initialize outputs y

 

      for (int k=1;k<p_test+1;k++)

      {

         for (int j=1;j<m+1;j++)

            {

            y[k][j]=0;

            }

      }

 

      // Calculate the bipolar outputs

 

      for (int k=1;k<p_test+1;k++)  // Loop over all the test patterns p_test

      {

                  for (int j=1;j<m+1;j++)

                  {    

                        y_in=0;

                        for (int i=1;i<n+1;i++)

                        {    

                           xi=S_new[k][i];

                           y_in=y_in+xi*w[i][j];

                        }  

                           y[k][j]=activationFunction(y_in);

 

                       

                  }

      }

 

//   Method that calculates the activation function

 

int activationFunction(int f)

{

      int fy=-1;

      if (f >= 0)

            fy=1;

      return fy;

}

Appendix C.  String representation y_out[ ] of the bipolar output y[ ][ ].

Bipolar output y

String representation y_out

1   -1   -1  -1   -1   -1   -1   -1   -1   -1   -1

A

-1   1   -1  -1   -1   -1   -1   -1   -1   -1   -1

B

-1   -1   1  -1   -1   -1   -1   -1   -1   -1   -1

C

-1   -1   -1  1   -1   -1   -1   -1   -1   -1   -1

D

Any other representation

*

Note that when the output is “*” is means that the net did not recognize the output.

Appendix D.  Format of the y_out.txt output data file.  Note that the values presented are examples and are not the actual outputs of the code.

Data output

k               Bipolar Output                   String Output

--  -------------------------------------------  -------------

 1   -1   1  -1  -1  -1  -1  -1  -1  -1  -1  -1        B 

 2    1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1        A 

 3   -1  -1  -1  -1  -1  -1  -1  -1  -1  -1  -1        * 

 4   -1  -1  -1  -1  -1  -1  -1  -1  -1   1  -1        * 

 .

 .

 .

16   -1  -1   1  -1  -1  -1  -1  -1  -1  -1  -1        C 

 

Appendix E.  Rubrics used for the calculation of the grade.

The rubrics used to calculate the grade in Excel is shown below.