Task to Complete
Create a program that “learns” with a perceptron through taking in an array of training data and adjusting its weights and threshold.
March 14th, 2017
- I spent this class creating my program structure, which I decided to be composed of a Perceptron class, a singleton Learner class to be used on a Perceptron, and a Runner that takes care of all of the graphics.
- I wrote the Perceptron class to take in inputs and weights, and to activate depending on a threshold. The Perceptron would be constructed based on its number of inputs/weights.
March 16th, 2017
- I spent this class developing my Learner class. I first created the basic singleton framwork (private constructor, static getInstance() method, etc.)
- I decided that it would work this way: a Perceptron, learning rate, and sample data would be inputted into the class and stored in instance variables. Then, there would be a learn method that returned a “learned” Perceptron based on these inputs.
- I began writing the learn method. It would first create a new temporary Perceptron that it would “learn” with that has one additional input/weight (for the threshold), and with a threshold of 0. Then, it would enter a do while loop that would loop until it reached a max iteration or the error from the previous iteration was zero. In the loop, it would loop through each piece of data, and for each piece of data, it would apply the learning rule (provided by Dr. Delgado) to each weight (including the threshold). If the delta weight was zero, then one additional error would be recorded.
- Once this process was complete, this temporary Perceptron would be converted back to a normal Perceptron with the appropriate weights and threshold. The original Perceptron’s index will be set to this one, and this Perceptron will be returned.
March 20th, 2017
- Today I finished up the learn method according to the original plan. This was done within 30 minutes or so.
- I spent the rest of the time developing the graphics. I used StdDraw this time – my second time trying it out. I found that it was pretty convenient for small-scale graphics projects like this one, particularly when the coordinates are important as you can define your own x and y scales in StdDraw.
- My graphics code would display the training data with dots (green or red), and draw a line depending on the current threshold and weights of the Perceptron.
March 21st, 2017
- Today, I finished up the graphics by drawing axis.
- However, I found a bug in my learning code. The end result would always be an extremely negative threshold, and all the weights would be wrong. I spent lots of time trying to debug my code, and added lots of println statements so I could see the process of the algorithm to try to isolate the problem.
- Eventually, I found that the problem was that the sum variable I used in the Perceptron class in the activate method was an integer, not a double, and hence rounded most fractional results to 0.
- As soon as I fixed this bug, my program worked.
March 22nd, 2017
- Today, with my code functional and meeting basic requirements, I added some additional features.
- These included using the console to choose between three training data input methods: using the preset And and Or Gate data, or a custom input method.
- The custom method allowed the user to click on the screen to create data points. At first all the points would be green, then pressing space allows the user to switch to red, and pressing it again starts the learning process.
- The largest problem I faced in adding these user interaction features was that I was not familiar with StdDraw. I found, contrary to my initial impression, that it was extremely awkward to use with regards to keyboard and mouse inputs, and lacked many capabilities that traditional Java graphics has – or maybe that’s just because I don’t fully know how to use StdDraw yet.
- In any case, at this point, my program is pretty much complete.