CS30 -- Introduction to Computer Science II
Fall, 2005
Assignment 3
(updated 9/12/2005)

From the text (Budd's Classic Data Structures in Java), Chapter 3, pg 66:
Do numbers 3 and 4.

Programming Projects:
1.  Build upon your pseudorandom number generator from last week.  (Again, this problem is adapted from Data Structures & Other Objects Using Java, Mark Main.) 

Create a new class, UniformRandNum, that extends your class from last week.  For purposes of this example, let's say you called your class MyRand.  Then UniformRandNum would extend MyRand.

First, if your MyRand class only had one constructor that took one or more arguments, add a second (default) constructor that takes zero arguments but initializes the seed, multiplier, increment and modulus to some reasonable values.  (The values given in Assignment 2 would be good candidates.)  Also, if your constructor from last week only took a seed argument, add yet another constructor that takes four arguements for seed, multiplier, increment, and modulus -- in that order.

Next, override your netxtElement().  This new version of the method should return a container class instance that holds a double type value between 0.0 (inclusive) and 1.0 (exclusive).  You can accomplish this by dividing the generated number by your modulus.  (Note, since the number generated by your method from last week is the remainder of a division by the modulus, it will never be greater than or equal to the modulus.  Therefore, when dividing by the modulus, the quotient will always be strictly less than 1.0.)  If one repeatedly calls this new method, it should generate a pseudorandom sequence in the range [0.0 .. 1.0). 

Ideally, this is the only method that you will need to override from your previous class.  (That is, your UniformRandNum class might only contain a default constructor and the one method, nextElement().)  However, if you need or want to make changes to your version of MyRand, feel free to do so.  Be sure to include a copy of your old class with your submission whether you alter it or not.

Once your new method is generating appropriate numbers, run experiments that evaluate the distribution of resulting numbers.  You'll probably run these experiments from a main method, perhaps in another class.  Break the range [0..1) into ten smaller ranges: [0.. 0.1), [0.1 .. 0.2), ... [0.9 .. 1.0).  For a large sequence of numbers, say a million, accumulate the number of pseudorandom numbers that were generated in each of these smaller ranges.  Finally, print out a table such as this:

Range   Number of Occurances
[0.0..0.1)   99889
[1.0..0.2)   100309
[0.9..1.0)   99904

Run your experiment several times with different values for the multiplier, increment, and modulus.  A set of good choices for these will yield approximately 10% of the total in each range.  A generator with this equal-interval behavior is called uniformly distributed.  Try to find a set of values that produce a better distribution than the values recommended in Assignment 2.

2.  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 function based on a linear weighted sum of their inputs and an activation function that determines the output signal of the unit by comparing the weighted sum to a particular threshold.  That is, weighted sum is the input to the activation function, which is usually either a threshold function or a sigmoid function. 

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

In fact, your class should implement the NeuralNetUnit interface that I provide.  At this stage, there are seven public methods required by the interface.  (In the weeks to come, we will elaborate the interface as we implement a full-fledged neural network.) 

Submission Instructions:
On your machine where you are doing your homework, create a folder called <your email name> followed by "A3".  For example, someone with email address "cjones" would create a folder called "cjonesA3".  Inside that folder, place plain text file(s) containing your answers to any exercises.  Also, place whatever Java files are necessary for your Programming Projects in the same folder.  Finally, either tar or zip the folder so that when I extract it, the folder "<emailname>A3" will be created.  Submit your file via Eureka.