Project 2: The Perceptron

"What, we asked, wasn't the Perceptron capable of?"
Rival, The New Yorker, December 6, 1958 P. 44

Introduction

In this project, you will implement a simple Perceptron classifier to classify digits (or anything else). But before you get started, you need to update your code on whatever computer you want to use.

Simply call:

svn update

The code for this project (project02) consists of several files, some of which you will need to read and understand in order to complete the assignment, and some of which you can ignore.

Files you'll edit:
codename.txtThis file contains some codename that represents you on the leaderboard. You can change your codename anytime you want, but please avoid offensive or annoying names (e.g. no names of other class mates, no swear words, no inappropriate body parts, urls, javascripts,...)
partners.txtIf you work in a group, this file should contain the NetID of your group partner. There should be nothing else in this file. Please make sure that your partner also puts you in his/her partners.txt file, as project partnerships must be mutual.
perceptronUpdate.mUpdate the weight vector based on the data.
perceptron.mA loop that calls perceptronUpdate.m.
classifyLinear.mGiven new data, use your linear classifier to classify it.
Files you might want to look at:
hw02tests.mRuns several unit tests to find obvious bugs in your implementation.

How to submit: You can commit your code with subversion, with the command line

svn commit -m "some meaningful comment"
where you should substitute "some meaningful comment" with something that describes what you did. You can submit as often as you want until the deadline. Please be aware that the last submission determines your grade.

Evaluation: Your code will be autograded for technical correctness. Please do not change the names of any provided functions or classes within the code, or you will wreak havoc on the autograder. However, the correctness of your implementation -- not the autograder's output -- will be the final judge of your score. If necessary, we will review and grade assignments individually to ensure that you receive due credit for your work.

Academic Dishonesty: We will be checking your code against other submissions in the class for logical redundancy. If you copy someone else's code and submit it with minor changes, we will know. These cheat detectors are quite hard to fool, so please don't try. We trust you all to submit your own work only; please don't let us down. If you do, we will pursue the strongest consequences available to us.

Getting Help: You are not alone! If you find yourself stuck on something, contact the course staff for help. Office hours, section, and the Piazza are there for your support; please use them. If you can't make our office hours, let us know and we will schedule more. We want these projects to be rewarding and instructional, not frustrating and demoralizing. But, we don't know when or how to help unless you ask.

The Perceptron

The perceptron is a basic linear classifier. The following questions will ask you to finish these functions in a pre-defined order. Unless specified otherwise, do not use loops.

(a) Implement the process of updating the weight vector in perceptronUpdate.m .

(b) Implement the loop that calls perceptronUpdate until it converges or the maximum iteration count, 100, has been reached in perceptron.m to get the weight vector. Make sure you randomize the order of the training data on each iteration. You can use loops for this function.

(c) Implement classifyLinear.m that applies the weight vector and bias to the input vector. (The bias is an optional parameter. If it is not passed in, assume it is zero.)

You can now test your classifier by calling visPerceptron2d and visPerceptronDigits or visPerceptronDigitsFast, which are similar to the demos shown in class. Please copy digits.mat from Project 01 to your Project 02 directory first to run visPerceptronDigits and visPerceptronDigitsFast. In all of these cases, your classifier should find a separating hyperplane.

Hints

randperm Returns a vector with the numbers [1,n] in a random permutation.

Tests. To test your code you can run hw02tests, which runs several unit tests. As your project progresses, slowly but surely these tests should stop failing.

Credits

Parts of this webpage were copied from or heavily inspired by John DeNero's and Dan Klein's (awesome) Pacman class.