Task to Complete

Create a program that uses a single perceptron to find a line to separate two “half-moons” of randomly generated data (see image).


April 3rd, 2017

  • I spent this class creating my program structure, which I decided to be composed of a Perceptron class, a singleton Trainer class to be used on a Perceptron, and a Runner that takes care of all of the graphics.
  • I copied the Perceptron and Trainer classes from the previous Perceptron project.

April 5th, 2017

  • I spent today refining and streamlining my old Perceptron and Trainer classes.  I was able to rewrite both of them in fewer lines of code.
  • I also played around a bit with different ways of storing the sample data.  Originally, I used an array for each piece of data with the inputs at the front and the output at the end.  Then, I switched to having an array of arrays where each outer array represents is a different output (i.e. 0 or 1), and each array within is the inputs that will lead to the corresponding output.  However, I ultimately abandoned this idea because it made the storage of data inflexible; furthermore, it was also difficult to shuffle data stored in such a method.
  • Hence, I decided to use the original method.  (I made a minor tweak by storing the output before the inputs such that when training, the data array could directly be used as the input array by just changing the first index to a -1, without having to slide everything left an index.)

April 7th, 2017

  • Today I finished up the project.  I first wrote a method for creating the data (the two half-moons) based on polar coordinates, where each point would be at a random bounded distance along a random angle (between 0 to pi for the first half-moon and pi to 2 pi for the second half-moon).  Then, the converted Cartesian x and y coordinates would be stored as inputs, and either 0 or 1 as outputs, in the method described above.
  • I also wrote the display using StdDraw, using my code from last time as a basis.  It would display the points as dots, with the border being the color it should be (red or blue) and the fill being the way it is currently classified by the Perceptron.  The display would also show the Perceptron as a line, as well as information such as the current iteration and the percent error.
  • *Note: I recently updated my version of StdDraw, so my graphics for this project, unlike previous StdDraw projects, uses double buffering.
Advertisements