Due date: Tuesday, April 22, 2008.
In this program we'll apply a simple neural networks to configuring a Julia Set fractal like this one.
Ex. 1 Download the following files:
bpnn.py
py_frac.py
The first one contains the implementation of a small neural network. You can run the script to see a demo of the network. Basically to use this module you need to create an object of the class NN with 3 parameters representing the number of inputs, number of nodes in the hidden layer, and the number of outputs.
The neural network is trained by providing data in a list where each element is a list with two elements, the first being a list of all the inputs (even if there's only one) and the second being a list of all the output for that particular set of inputs. The outputs must be values between 0 and 1.
Add a second demo function in the file bpnn.py that build a network with 3 inputs, three hidden nodes and one output. Create the set of data containing some examples for the expression A & B => C, but not all of them. Test the system in the demo function on the other values and report on how well the system answers them. Note that to get the answer of the system to one particular set of inputs, you need to call the function update with the inputs provided as a list, and the value returned by this function call is the result.
Ex. 2 The second file contains some functions to draw a Julia Set fractal into a file called "result.png". The script is already updated so that the palette of colors is determined using a neural network.
a. Change the script such that it can take the name of the resulting image file as parameter in argv. If a parameter is not provided, then use the default name result.png.
b. Add another neural network in the file py_frac.py that learns to provide a complementary color to one that it is given. This network would have 3 inputs and 3 outputs and as many hidden nodes as you want. The colors are represented as r g b values in the range 0-1.
Provide a set of examples for the training that are colors that you think would match well (they must provide a good contrast, but they don't have to be opposite) and train the second neural network on them. Then generate one random color and get an opposite one as a result of the output of the new NN. Plus in these two colors as the training samples for the input values 0 and 1 for the first NN (the one already there) to generate the palette.
Experiment with the scripts and send me the best image that you generated with this method. You can change other parameters (like add another color data point in the middle or increase the number of generated colors) if you think that they will improve the image.
Turn in: the two script files and your favorite resulting image.