CPSC 420-500 Program 3: Perceptron and Backpropagation - Prof. Y. Choe, Assignments of Computer Science

An assignment for a computer science course at texas a&m university, where students are required to implement perceptron and backpropagation algorithms from scratch. The assignment involves training the models on and, or, and xor functions, and reporting findings. Students may use c/c++, java, matlab, or lisp, and must submit the code, executable binary, readme file, and plots for evaluation.

Typology: Assignments

Pre 2010

Uploaded on 02/13/2009

koofers-user-ais-2
koofers-user-ais-2 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CPSC 420-500: Program 3, Perceptron and
Backpropagation
Yoonsuck Choe
Department of Computer Science
Texas A&M University
November 2, 2007
1 Overview
You will implement perceptron learning from scratch (see section 3 for details), and
train it on AND, OR, and XOR functions. Then, you will take an existing backprop-
agation code (see section 4), train it and test it under different conditions and report
your findings. The same three boolean functions will be used for the backpropagation
learning. For further details on perceptrons and backpropagation, see the lecture slides
and also Hertz et al. (1991). Specific submission instruction will be given in section 5
and section 6.
2 Language and OS
You may use either C/C++, Java, Matlab (or Octave), or Lisp. The resulting code
should be able to compile and run on the departmental unix hosts (unix.cs.tamu.edu,
compute.cs.tamu.edu, interactive.cs.tamu.edu). You may use a different language with
a permission from the instructor, in which case you will be asked to do a demo in front
of the TA.
To compile your programs other than Lisp (which you already know), see the following
instructions.
C program file: perceptron.c
to compile: cc -o perceptron perceptron.c -lm
to execute: ./perceptron
C++ program file: perceptron.C
to compile: c++ -o perceptron perceptron.C -lm
1
pf3
pf4
pf5

Partial preview of the text

Download CPSC 420-500 Program 3: Perceptron and Backpropagation - Prof. Y. Choe and more Assignments Computer Science in PDF only on Docsity!

CPSC 420-500: Program 3, Perceptron and

Backpropagation

Yoonsuck Choe

Department of Computer Science

Texas A&M University

November 2, 2007

1 Overview

You will implement perceptron learning from scratch (see section 3 for details), and train it on AND, OR, and XOR functions. Then, you will take an existing backprop- agation code (see section 4), train it and test it under different conditions and report your findings. The same three boolean functions will be used for the backpropagation learning. For further details on perceptrons and backpropagation, see the lecture slides and also Hertz et al. (1991). Specific submission instruction will be given in section 5 and section 6.

2 Language and OS

You may use either C/C++, Java, Matlab (or Octave), or Lisp. The resulting code should be able to compile and run on the departmental unix hosts (unix.cs.tamu.edu, compute.cs.tamu.edu, interactive.cs.tamu.edu). You may use a different language with a permission from the instructor, in which case you will be asked to do a demo in front of the TA.

To compile your programs other than Lisp (which you already know), see the following instructions.

  • C program file: perceptron.c to compile: cc -o perceptron perceptron.c -lm to execute: ./perceptron
  • C++ program file: perceptron.C to compile: c++ -o perceptron perceptron.C -lm

to execute: ./perceptron

  • Java program file: perceptron.java to compile: javac perceptron.java to execute: java perceptron

The full paths for the compilers are (on compute.cs.tamu.edu):

  • /usr/local/SUNWspro/bin/cc
  • /usr/local/bin/g++
  • /usr/local/java/j2se/bin/java
  • /usr/local/java/j2se/bin/javac

3 Perceptron

Perceptron activation is defined as:

Output = step

i=

W [i] ∗ IN P [i]

where step(X) = 1 if X ≥ 0 and step(X) = 0 if X < 0 (see figure 1).

W[0] W[1] W[2]

−1 X Y

f(X,Y)

INP[0] INP[1] INP[2]

Figure 1: Perceptron. The input IN P [0] is the bias unit, fixed to − 1 , and has an associated weight W [0], which is the threshold. The two inputs X and Y are given and the output f (X, Y ) will be calculating (or attempting to calculate) a boolean function, one of OR, AND, or XOR.

Implement a perceptron with two input units (three, including the bias unit that has a fixed input value -1) and one output unit. Your program should take three inputs from the keyboard (i.e. standard input):

  1. maximum number of epochs to run (integer),
  2. learning rate parameter α value (double),

$ ./bp conf/xor.conf | grep ERR

and to view the actual output values for the inputs:

$ ./bp conf/xor.conf | grep OUT

5 Assignment

This section will detail what you actually have to do and have to submit. All projects should be turned in using the csnet turnin.

5.1 Perceptron

Implement perceptron learning algorithm as detailed in section 3, and with the program conduct the following experiments, and submit the required material, along with the code and the README file as usual.

Experiments:

  1. Test AND, OR, and XOR for learning rates α = 0.001, and 0.0001. For each Boolean function, run the experiment with different initial random weights (use the random number generator function to do this) three times. Discard all runs that ended in 1 epoch (you will see several of these: why would they occur?). The total number of trial will thus be 18. Set the max epoch to 10000 for all trials.
  2. For each trial, report the following in the README file:

(a) initial weights, and show the plot of the decision boundary (the straight line defined by the weights). (b) final weights, and show the plot of the decision boundary. (c) number of epochs taken to complete training if successful (let us call this n), and (d) for each epoch, the sum of squared error for all four input patterns.

  1. Answer these questions in the README file:

(a) How dependent is n on the initial weights? (b) Do you think perceptron will be able to learn the boolean function f (X, Y ) = ¬(X ∨ Y )? What do you think is the role of the sign of the weights in this case? Think about the geometric interpretation in that case.

Table 1: Boolean Function f (X, Y ) = ¬(X ∨ Y ). X Y ¬(X ∨ Y ) 0 0 1 0 1 0 1 0 0 1 1 0

5.2 Backpropagation

With the provided code, conduct experiments on AND, OR, and XOR. Note that in the bp.cc code, learning rate α is a named eta, just in case you want to take a look inside the code.

Experiments:

  1. Test AND, OR, and XOR for learning rates α = 0.01, 0.001, and 0.0001, and plot the sum of squared error for each trial (a total of 9 trials). A total of 3 set of plots (for AND, OR, and XOR), with each set containing 3 curves (for three α’s) is required. Save the plots in image files and name them b1-plot0.jpg, b1-plot1.jpg, ....
  2. With learning rate α = 0. 001 , test AND, OR, and XOR, with 1, 2, 3, and 4 hidden units, Plot the sum of squared error for each trial. A total of 3 set of plots (for AND, OR, and XOR), with each set containing 4 curves (for four different number of hidden units) is required. Save the plots in image files and name them b2-plot0.jpg, b2-plot1.jpg, ....
  3. For all trials above, count the number of epochs until the end is reached, and measure the time taken using the timex unix command:

timex ./bp conf/xor.conf

Report the number of epochs and time spent for each trial in the README file. How many number of hidden units was the best in your opinion and why?

6 Submission Details

The due date is 12/7/2006, 11:59pm. Grading criteria will be similar to the previous programming assignments. You must submit the following:

  • source code,
  • compiled executable binary,