Not logged in. Login

Assignment 4

In this assignment you will implement the backpropagation algorithm for learning the weights of a neural network.

Download the code template here. You should write your code between the comments marked "Begin/End your code". You may add extra functions as you like.

You will implement four functions. calculate() applies the neural network to a given input and returns the output of the network (i.e. the output of the last neuron). squared_error() calculates the error of the network on a set of examples. backpropagate_example() applies the backpropagation algorithm to learn the weights for a given example. learn() repeatedly applies the backpropagation algorithm to each of the input examples, repeating num_epochs times (that is, for 4 examples and 100 epochs, learn() will call backpropagate_example() 400 times.)

You will use your code to learn a network that implements the XOR function. The code defines a framework you can use to test your code. It defines four examples, with the attributes and labels in example_attributes and example_labels respectively. You should generate a random initial ANN using random_ann() and train it using ANN.learn(), using a learning rate of 10 and 10,000 epochs. Train for 10 separate initializations and choose the one that achieved the best squared error. Hard-code your best trained model in your solution file.

Guidelines

Please use Python 3 for this assignment.

100 points total, worth 10% of the course grade. Turn in on CourSys. Submit a single file named "a4.py".

Grading: Your solution will be evaluated on accuracy and clarity. Solutions that are hard to understand will be given a maximum of 50/100 points. Please use a logical structure, use informative variable names, and document your code thoroughly so that your solution is understandable.

You are encouraged to work in a group. Feel free to discuss solution strategies and check each other’s work. However, you must write all the text and code you submit on your own. Joint submissions are not allowed, nor is copying someone else's text or code. Plagiarism is not okay, and will be taken very seriously. If you’re not sure whether something is okay, please ask.

If you are having trouble, please take advantage of office hours and the discussion forum. If you see a question from another student on the discussion forum that you think you know the answer to, please respond. (Do your best to lead your fellow student to a solution, rather than simply giving the solution directly.)

Updated Thu Nov. 23 2017, 22:07 by maxwl.