Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.NeuralNetwork.BackPropagation.Network.BasicNetwork Class Reference

List of all members.

Public Member Functions

def __init__
def train
def predict

Private Attributes

 _input
 _hidden
 _output

Detailed Description

Represent a Basic Neural Network with three layers.

This deals with a Neural Network containing three layers:

o Input Layer

o Hidden Layer

o Output Layer

Definition at line 17 of file Network.py.


Constructor & Destructor Documentation

def Bio.NeuralNetwork.BackPropagation.Network.BasicNetwork.__init__ (   self,
  input_layer,
  hidden_layer,
  output_layer 
)
Initialize the network with the three layers.

Definition at line 28 of file Network.py.

00028 
00029     def __init__(self, input_layer, hidden_layer, output_layer):
00030         """Initialize the network with the three layers.
00031         """
00032         self._input = input_layer
00033         self._hidden = hidden_layer
00034         self._output = output_layer

Here is the caller graph for this function:


Member Function Documentation

Predict outputs from the neural network with the given inputs.

This uses the current neural network to predict outputs, no
training of the neural network is done here.

Definition at line 96 of file Network.py.

00096 
00097     def predict(self, inputs):
00098         """Predict outputs from the neural network with the given inputs.
00099 
00100         This uses the current neural network to predict outputs, no
00101         training of the neural network is done here.
00102         """
00103         # update the predicted values for these inputs
00104         self._input.update(inputs)
00105 
00106         output_keys = self._output.values.keys()
00107         output_keys.sort()
00108 
00109         outputs = []
00110         for output_key in output_keys:
00111             outputs.append(self._output.values[output_key])
00112         return outputs

Here is the caller graph for this function:

def Bio.NeuralNetwork.BackPropagation.Network.BasicNetwork.train (   self,
  training_examples,
  validation_examples,
  stopping_criteria,
  learning_rate,
  momentum 
)
Train the neural network to recognize particular examples.

Arguments:

o training_examples -- A list of TrainingExample classes that will
be used to train the network.

o validation_examples -- A list of TrainingExample classes that
are used to validate the network as it is trained. These examples
are not used to train so the provide an independent method of
checking how the training is doing. Normally, when the error
from these examples starts to rise, then it's time to stop
training.

o stopping_criteria -- A function, that when passed the number of
iterations, the training error, and the validation error, will
determine when to stop learning.

o learning_rate -- The learning rate of the neural network.

o momentum -- The momentum of the NN, which describes how much
of the prevoious weight change to use.

Definition at line 36 of file Network.py.

00036 
00037               stopping_criteria, learning_rate, momentum):
00038         """Train the neural network to recognize particular examples.
00039 
00040         Arguments:
00041 
00042         o training_examples -- A list of TrainingExample classes that will
00043         be used to train the network.
00044 
00045         o validation_examples -- A list of TrainingExample classes that
00046         are used to validate the network as it is trained. These examples
00047         are not used to train so the provide an independent method of
00048         checking how the training is doing. Normally, when the error
00049         from these examples starts to rise, then it's time to stop
00050         training.
00051 
00052         o stopping_criteria -- A function, that when passed the number of
00053         iterations, the training error, and the validation error, will
00054         determine when to stop learning.
00055 
00056         o learning_rate -- The learning rate of the neural network.
00057 
00058         o momentum -- The momentum of the NN, which describes how much
00059         of the prevoious weight change to use.
00060         """
00061         num_iterations = 0
00062         while 1:
00063             num_iterations += 1
00064             training_error = 0.0
00065             for example in training_examples:
00066                 # update the predicted values for all of the nodes
00067                 # based on the current weights and the inputs
00068                 # This propogates over the entire network from the input.
00069                 self._input.update(example.inputs)
00070 
00071                 # calculate the error via back propogation
00072                 self._input.backpropagate(example.outputs,
00073                                           learning_rate, momentum)
00074             
00075                 # get the errors in our predictions
00076                 for node in range(len(example.outputs)):
00077                     training_error += \
00078                              self._output.get_error(example.outputs[node],
00079                                                     node + 1)
00080 
00081             # get the current testing error for the validation examples
00082             validation_error = 0.0
00083             for example in validation_examples:
00084                 predictions = self.predict(example.inputs)
00085 
00086                 for prediction_num in range(len(predictions)):
00087                     real_value = example.outputs[prediction_num]
00088                     predicted_value = predictions[prediction_num]
00089                     validation_error += \
00090                             0.5 * math.pow((real_value - predicted_value), 2)
00091 
00092             # see if we have gone far enough to stop
00093             if stopping_criteria(num_iterations, training_error,
00094                                  validation_error):
00095                 break

Here is the call graph for this function:


Member Data Documentation

Definition at line 32 of file Network.py.

Definition at line 31 of file Network.py.

Definition at line 33 of file Network.py.


The documentation for this class was generated from the following file: