Back to index

python-biopython  1.60
Functions | Variables
test_NNExclusiveOr Namespace Reference

Functions

def main
def stopping_criteria

Variables

int VERBOSE = 0

Function Documentation

Train a neural network, and then test it to see how it does.

Since we have so few examples, we use all of them for training,
validation and testing.

Definition at line 14 of file test_NNExclusiveOr.py.

00014 
00015 def main():
00016     """Train a neural network, and then test it to see how it does.
00017 
00018     Since we have so few examples, we use all of them for training,
00019     validation and testing.
00020     """
00021     print "Setting up training examples..."
00022     # set up the training examples
00023     examples = []
00024     examples.append(TrainingExample([0, 0], [0]))
00025     examples.append(TrainingExample([0, 1], [1]))
00026     examples.append(TrainingExample([1, 0], [1]))
00027     examples.append(TrainingExample([1, 1], [0]))
00028 
00029     # create the network
00030     output = Layer.OutputLayer(1)
00031     hidden = Layer.HiddenLayer(3, output)
00032     input = Layer.InputLayer(2, hidden)
00033     
00034     network = BasicNetwork(input, hidden, output)
00035 
00036     print "Training the network..."
00037     # train it
00038     learning_rate = .5
00039     momentum = .1
00040     network.train(examples, examples, stopping_criteria, learning_rate,
00041                   momentum)
00042 
00043     print "Predicting..."
00044     # try predicting
00045     for example in examples:
00046         prediction = network.predict(example.inputs)
00047         if VERBOSE:
00048             print "%s;%s=> %s" % (example.inputs, example.outputs, prediction)

Here is the caller graph for this function:

def test_NNExclusiveOr.stopping_criteria (   num_iterations,
  validation_error,
  training_error 
)
Define when to stop iterating.

Definition at line 49 of file test_NNExclusiveOr.py.

00049 
00050 def stopping_criteria(num_iterations, validation_error, training_error):
00051     """Define when to stop iterating.
00052     """
00053     if num_iterations % 100 == 0:
00054         if VERBOSE:
00055             print "error:", validation_error
00056     if num_iterations >= 2000:
00057         return 1
00058 
00059     return 0
00060 
00061 main()

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 11 of file test_NNExclusiveOr.py.