Homework Four: Random Walks and Introduction to Neural Networks

Part 1: Random Walks

Purpose: use what you learned in the Planets and Stars lab and learn about random walks.

Random walks are interesting constructs that have been used to model many physical processes and phenomena. In the classic formulation, an agent starts at an origin and flips a fair coin. If the coin comes up heads, the agent moves one step to the left; otherwise it moves one step to the right. This gets repeated until the agent falls off one edge or the other.

Using some of the framework we created for the Planets and Stars lab, create a RandomWalk class that (1) displays a window with the agent starting in the middle of a horizontal line near the bottom, (2) and shows the agent moving left and right (you can draw the agent as a circle or rectangle) as you simulate flipping the coin. (3) Your display should also show the number of times the agent has landed on this square as a dot above the line, where the height above the line corresponds to the number of times (but may be scaled by some number in order to keep the dots from running off the screen or from being hidden by the horizontal line). You should use an array of ints with a length that is as wide as your window. Each pixel of the window will correspond to one cell.

Once you have the above working, (4) modify your class to repeat the process, starting the agent back at the center once it reaches one edge or the other, but continue to accumulate the counts. (5) The number of times to repeat the process should be a command line argument that you extract from the Strings[] args in your main method. (6) Your display should dynamically rescale as the counts accumulate and exceed the height of your window.

Part 2: Introduction to Neural Networks

You will write the first part of a neural network. A linear threshold unit (LTU) is the fundamental building block of a neural network. This week, you will write a class that implements the functionality of a LTU. These units compute a single output value based a number of inputs. The output of a unit is determined by computing a linear weighted sum of its inputs and their corresponding weights, and using this sum as the input to an activation function. You might think of the activation function as using a threshold; if the activation is below the threshold, the output is 0, and if it is above the threshold the output is 1. In other words, the weighted sum is the input to the activation function, which is usually either a threshold function (as just described) or a sigmoid function (which we'll talk about later).

A single LTU can implement the boolean operators, AND, OR and NOT. For example, a unit with two inputs (x1 and x2 with corresponding weights w1=1 and w2=1) and threshold of 1.5 computes the logical conjunction (AND) of its two inputs (with input values either 1 or 0).

For this part of the assignment, you should write a class, MyLTU. Your class should implement the NeuralNetUnit interface that I provide (the java source for the interface is provided on the Eureka page). There are currently eleven public methods prescribed by the interface. At this stage, there are eight public methods (two of which are deprecated but which must still be implemented) that you should implement. (For now, you should throw UnsupportedOperationException for the last three methods in the interface. Later, we will implement those as well.) Your inputs should be Integer wrapper objects containing 0/1 values for input to the LTU.

For reasons that will become clear later, it is convenient to think of the threshold as just another weight and store it in the zero-indexed location for the LTU.

Your class should include a constructor that takes a single int value indicating how many inputs the unit combines. For example, you might want to create an instance with two inputs and then set the weights and threshold according to the example above. Or you can experiment with other boolean functions on two or more inputs of your own choosing.

Submission instructions:

Do not forget to use the javadoc constructs for your documentation and include the html file produced by the javadoc tool in your final submission. Make sure that you create a folder named with your Westmont email name followed by "HW4". For example, someone with email address "cjones" would create a folder called "cjonesHW4". Make sure that inside that folder you have: java source files as well as html documentation files resulting from javadoc. Finally, either tar or zip the folder so that when we extract it, the folder "<emailname>HW4" will be created. Submit the packaged file for assignment 3 on Eureka.