import bpnn def test1 () : """ This function trains and tests a neural network that computs an exclusive or; that is, the neural net outputs one if either of the inputs is 1 but not both. """ print "\nXOR\n" # This is a list of training patterns. Each training pattern is # itself a list which contains two lists: a list of inputs and # a list of desired/target outputs training_patterns = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]] ] # In this case, the test patterns are the same as the training patterns. test_patterns = training_patterns # This defines the structure of the network. We have 2 input # units, 2 hidden units and 1 output unit. The number of input # and ouput units is determined by the task we want the network # to solve, the best number of hidden units needs to be experimentally # determined. Try what happens when you use more or fewer hidden units. n = bpnn.NN(2, 2, 1) n.train(training_patterns) n.test(test_patterns) def test2 () : """ This function is supposed to train and test a neural network that computes a boolean and; that is, it should output 1 if and only if both inputs are 1. Hint: use 2 hidden units. """ print "\nAND\n" def test3 () : """ This function is supposed to train and test a neural network that decides whether the input represents a binary number that is divisble by 3. Use 4 input units (which will allow you to represent numbers 0,..,15) and 2 or 3 hidden units. """ print "\ndivisible by 3\n" #test1() #test2() #test3()