Question: In this lab, we will attempt to train perceptrons on a number of simple learning problems using python's numpy library . Heres the general procedure

In this lab, we will attempt to train perceptrons on a number of simple learning problems using python's numpy library . Heres the general procedure for training a perceptron in Python:

I Store your training data in a pair of variables X, D. The X variable should be a list of vectors which are the inputs to the perceptron (including a final 1 for the bias) and the D variable should be a list of vectors with the desired output.

II Initialize the weights to random numbers between 0 and 1.

III For some number of epochs, iterate through the lists X and D and calculate the actual output of the perceptron based on input X. Call this Y. Use the perceptron learning rule to update the weights: w = w + (D Y )X

IV It is helpful to keep track of the error for an epoch as you train. If the training data consists of x1, x2, . . . , xn with desired outputs d1, d2, . . . dn, if the actual outputs are y1, y2, . . . , yn then the total error for that epoch is 1 /2 ||D Y|| where D is the vector [d1 d2 . . . dn]^ T and Y is the vector [ y y1 y2 . . . yn] ^T

The perceptron has learned the function perfectly when the error is 0.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!