Package pyrobot :: Package brain :: Module conx :: Class Network
[frames | no frames]

Class Network

Known Subclasses:
GovernorNetwork, SRN

Class which contains all of the parameters and methods needed to
run a neural network.

Method Summary
  __init__(self, name, verbosity)
Constructor for the Network class.
  __getitem__(self, name)
Returns the layer specified by name.
  __len__(self)
Returns the number of layers in the network.
  __str__(self)
Returns string representation of network.
  activationFunction(self, x)
Determine the activation of a node based on that nodes net input.
  ACTPRIME(self, act)
Used in compute_error.
  add(self, layer, verbosity)
Adds a layer.
  addLayer(self, name, size, verbosity)
  addPattern(self, word, vector)
Adds a pattern with key word.
  addThreeLayers(self, inc, hidc, outc)
Creates a three layer network with 'input', 'hidden', and 'output' layers.
  arrayify(self)
Returns an array of node bias values and connection weights for use in a GA.
  associate(self, inName, outName)
inName layer and outName layer will be auto-associating.
  backprop(self)
Computes error and wed for back propagation of error.
  ce_init(self)
Initializes error computation.
  change_weights(self)
Changes the weights according to the error values calculated during backprop().
  changeLayerSize(self, layername, newsize)
Changes layer size.
  closeLog(self, layerName)
Close the layerName's log file.
  compare(self, v1, v2)
Compares two values.
  compute_error(self)
Computes error for all non-output layers backwards through all projections.
  compute_wed(self)
Computes weight error derivative for all connections in self.connections starting with the last connection.
  connect(self, fromName, toName)
Connects two layers by instantiating an instance of Connection class.
  copyActivations(self, layer, vec, start)
Copies activations in vec to the specified layer, replacing patterns if necessary.
  copyTargets(self, layer, vec, start)
Copies targets in vec to specified layer, replacing patterns if necessary.
  copyVector(self, vector1, vec2, start)
Copies vec2 into vector1 being sure to replace patterns if necessary.
  cycle(self)
Alternate to sweep().
  delPattern(self, word)
Delete a pattern with key word.
  diff(self, value)
Returns value to within 0.001.
  display(self)
Displays the network to the screen.
  getActivationsDict(self, nameList)
Returns a dictionary of layer names that map to a list of activations.
  getActive(self, layerName)
Returns the value of the active flag for the layer specified by layerName.
  getConnection(self, lfrom, lto)
Returns the connection instance connecting the specified (string) layer names.
  getCorrect(self, layerName)
Returns the number of correct activation within tolerance of a layer.
  getData(self, pos)
Returns dictionary with input and target given pos.
  getDataCrossValidation(self, pos)
  getEpsilon(self)
Returns the epsilon for the Network instance.
  getError(self, *layerNames)
  getLayer(self, name)
Returns the layer with the argument (string) name.
  getLayerIndex(self, layer)
Given a reference to a layer, returns the index of that layer in self.layers.
  getPattern(self, word)
Returns the pattern with key word.
  getWeights(self, fromName, toName)
Gets the weights of the connection between two layers (argument strings).
  getWord(self, pattern)
Returns the word associated with pattern.
  initialize(self)
Initializes network by calling Connection.initialize() and Layer.initialize().
  loadCrossValidation(self, filename)
  loadDataFromFile(self, filename, ocnt)
Loads data (targets/inputs) from file.
  loadInputPatternsFromFile(self, filename, cols, everyNrows, delim, checkEven)
Loads inputs as patterns from file.
  loadInputsFromFile(self, filename, cols, everyNrows, delim, checkEven)
Loads inputs from file.
  loadTargetPatternssFromFile(self, filename, cols, everyNrows, delim, checkEven)
Loads targets as patterns from file.
  loadTargetsFromFile(self, filename, cols, everyNrows, delim, checkEven)
Loads targets from file.
  loadVectorsFromFile(self, filename, cols, everyNrows, delim, checkEven, patterned)
Load a set of vectors from a file.
  loadWeightsFromFile(self, filename, mode)
Loads weights from a file in pickle, plain, or tlearn mode.
  logLayer(self, layerName, fileName)
Sets the layerName's log feature.
  logMsg(self, layerName, message)
Logs a message with layerName log.
  mapInput(self, layerName, offset)
Adds layerName and offset to inputMap.
  mapInputs(self, nameOffsetPairs)
  mapTarget(self, layerName, offset)
Adds layerName and offset to targetMap.
  mapTargets(self, nameOffsetPairs)
  path(self, startLayer, endLayer)
Used in error checking with verifyArchitecture() and in prop_from().
  patternVector(self, vector)
Replaces vector with patterns.
  postStep(self)
  postSweep(self)
  preStep(self)
  preSweep(self)
  Print(self, msg)
  prompt(self)
  prop_from(self, startLayers)
Start propagation from the layers in the list startLayers.
  propagate(self, **args)
Propagates activation through the network.
  propagateFrom(self, startLayer, **args)
Propagates activation through the network.
  putActivations(self, dict)
Puts a dict of name: activations into their respective layers.
  randomizeOrder(self)
Randomizes self.loadOrder, the order in which inputs set with self.setInputs() are presented.
  replacePatterns(self, vector)
Replaces patterned inputs or targets with activation vectors.
  reportEpoch(self, epoch, tssErr, totalCorrect, totalCount, rmsErr)
  reportFinal(self, epoch, tssErr, totalCorrect, totalCount, rmsErr)
  reportPattern(self)
  reportStart(self)
  reset(self)
Resets seed values.
  resetFlags(self)
Resets layer flags for activation and target.
  RMSError(self)
Returns Root Mean Squared Error for all output layers in this network.
  saveDataToFile(self, filename)
Saves data (targets/inputs) to file.
  saveInputsToFile(self, filename)
Saves inputs to file.
  saveNetworkForCrossValidation(self, filename, mode)
  saveNetworkToFile(self, filename, makeWrapper)
Saves network to file using pickle.
  saveTargetsToFile(self, filename)
Saves targets to file.
  saveWeightsToFile(self, filename, mode)
Saves weights to file in pickle, plain, or tlearn mode.
  setActive(self, layerName, value)
Sets a layer to active.
  setAutoCrossValidation(self, value)
  setAutoSaveWeightsFile(self, filename)
  setBatch(self, value)
Sets self.batch to value.
  setEpsilon(self, value)
Sets epsilon value for the network.
  setInputs(self, inputs)
Sets self.input to inputs.
  setInputsAndTargets(self, data1, data2)
Network.setInputsAndTargets() Sets the corpus of data for training.
  setInteractive(self, value)
Sets interactive to value.
  setLayerVerification(self, value)
  setLearning(self, value)
Sets learning to value.
  setMaxRandom(self, value)
Sets the maxRandom Layer attribute for each layer to value.Specifies the global range for randomly initialized values, [-max, max].
  setMomentum(self, value)
Sets self.momentum to value.
  setOrderedInputs(self, value)
Sets self.orderedInputs to value.
  setOutputs(self, outputs)
For compatiblity.
  setPattern(self, word, vector)
Sets a pattern with key word.
  setPatterned(self, value)
Sets the network to use patterns for inputs and targets.
  setPatterns(self, patterns)
Sets patterns to the dictionary argument.
  setReportRate(self, value)
Sets self.reportRate to value.
  setResetEpoch(self, value)
Sets self.resetEpoch to value.
  setResetLimit(self, value)
Sets self.resetLimit to value.
  setSeed(self, value)
Sets the seed to value.
  setSigmoid_prime_offset(self, value)
Sets self.sigmoid_prime_offset to value.
  setStopPercent(self, value)
Sets self.stopPercent to value.
  setSweepReportRate(self, value)
Sets self.sweepReportRate to value.
  setTargets(self, targets)
Sets the targets.
  setTolerance(self, value)
Sets tolerance to value.
  setup(self)
  setUseCrossValidationToStop(self, value)
Sets flag so that self.stopPercent is compared to cross validation percent rather than the regular training data percentage correct.
  setVerbosity(self, value)
Sets self.verbosity and each layer verbosity to value.
  setWeight(self, fromName, fromPos, toName, toPos, value)
Sets the weight of the connection between two layers (argument strings).
  shareWeights(self, network, listOfLayerNamePairs)
Share weights with another network.
  step(self, **args)
Network.step() Does a single step.
  sweep(self)
Runs through entire dataset.
  sweepCrossValidation(self)
sweepCrossValidation() will go through each of the crossvalidation input/targets.
  toString(self)
Returns the network layers as a string.
  train(self, cont)
Trains the network on the dataset till a stopping condition is met.
  TSSError(self, layerName)
Returns Total Sum Squared error for the specified layer's pattern.
  unArrayify(self, gene)
Copies gene bias values and weights to network bias values and weights.
  verifyArchitecture(self)
Check for orphaned layers or connections.
  verifyArguments(self, arg)
Verifies that arguments to setInputs and setTargets are appropriately formatted.
  verifyInputs(self)
Used in propagate() to verify that the network input activations have been set.
  verifyTargets(self)
Used in backprop() to verify that the network targets have been set.

Method Details

__init__(self, name='Backprop Network', verbosity=0)
(Constructor)

Constructor for the Network class. Takes optional name and
verbosity arguments.

__getitem__(self, name)
(Indexing operator)

Returns the layer specified by name.

__len__(self)
(Length operator)

Returns the number of layers in the network.

__str__(self)
(Informal representation operator)

Returns string representation of network.

activationFunction(self, x)

Determine the activation of a node based on that nodes net input.

ACTPRIME(self, act)

Used in compute_error.

add(self, layer, verbosity=0)

Adds a layer. Layer verbosity is optional (default 0).

addPattern(self, word, vector)

Adds a pattern with key word.

Example: net.addPattern("tom", [0, 0, 0, 1])

addThreeLayers(self, inc, hidc, outc)

Creates a three layer network with 'input', 'hidden', and
'output' layers.

arrayify(self)

Returns an array of node bias values and connection weights
for use in a GA.

associate(self, inName, outName)

inName layer and outName layer will be auto-associating.

backprop(self)

Computes error and wed for back propagation of error.

ce_init(self)

Initializes error computation. Calculates error for output
layers and initializes hidden layer error to zero.

change_weights(self)

Changes the weights according to the error values calculated
during backprop(). Learning must be set.

changeLayerSize(self, layername, newsize)

Changes layer size. Newsize must be greater than zero.

closeLog(self, layerName)

Close the layerName's log file.

compare(self, v1, v2)

Compares two values. Returns 1 if all values are withing
self.tolerance of each other.

compute_error(self)

Computes error for all non-output layers backwards through all
projections.

compute_wed(self)

Computes weight error derivative for all connections in
self.connections starting with the last connection.

connect(self, fromName, toName)

Connects two layers by instantiating an instance of Connection
class.

copyActivations(self, layer, vec, start=0)

Copies activations in vec to the specified layer, replacing
patterns if necessary.

copyTargets(self, layer, vec, start=0)

Copies targets in vec to specified layer, replacing patterns
if necessary.

copyVector(self, vector1, vec2, start)

Copies vec2 into vector1 being sure to replace patterns if
necessary. Use self.copyActivations() or self.copyTargets()
instead.

cycle(self)

Alternate to sweep().

delPattern(self, word)

Delete a pattern with key word.

Example: net.delPattern("tom")

diff(self, value)

Returns value to within 0.001. Then returns 0.0.

display(self)

Displays the network to the screen.

getActivationsDict(self, nameList)

Returns a dictionary of layer names that map to a list of activations.

getActive(self, layerName)

Returns the value of the active flag for the layer specified
by layerName.

getConnection(self, lfrom, lto)

Returns the connection instance connecting the specified (string)
layer names.

getCorrect(self, layerName)

Returns the number of correct activation within tolerance of a
layer.

getData(self, pos)

Returns dictionary with input and target given pos.

getEpsilon(self)

Returns the epsilon for the Network instance.

getLayer(self, name)

Returns the layer with the argument (string) name.

getLayerIndex(self, layer)

Given a reference to a layer, returns the index of that layer in
self.layers.

getPattern(self, word)

Returns the pattern with key word.

Example: net.getPattern("tom") => [0, 0, 0, 1]

getWeights(self, fromName, toName)

Gets the weights of the connection between two layers (argument strings).

getWord(self, pattern)

Returns the word associated with pattern.

Example: net.getWord([0, 0, 0, 1]) => "tom"

This method uses the net.compare() method to compute if the patterns
are the same. Tolerance is adjusted using net.setTolerance().

initialize(self)

Initializes network by calling Connection.initialize() and
Layer.initialize(). self.count is set to zero.

loadDataFromFile(self, filename, ocnt=-1)

Loads data (targets/inputs) from file.

loadInputPatternsFromFile(self, filename, cols=None, everyNrows=1, delim=' ', checkEven=1)

Loads inputs as patterns from file.

loadInputsFromFile(self, filename, cols=None, everyNrows=1, delim=' ', checkEven=1)

Loads inputs from file. Patterning is lost.

loadTargetPatternssFromFile(self, filename, cols=None, everyNrows=1, delim=' ', checkEven=1)

Loads targets as patterns from file.

loadTargetsFromFile(self, filename, cols=None, everyNrows=1, delim=' ', checkEven=1)

Loads targets from file.

loadVectorsFromFile(self, filename, cols=None, everyNrows=1, delim=' ', checkEven=1, patterned=0)

Load a set of vectors from a file. Takes a filename, list of cols
you want (or None for all), get every everyNrows (or 1 for no
skipping), and a delimeter.

loadWeightsFromFile(self, filename, mode='pickle')

Loads weights from a file in pickle, plain, or tlearn mode.

logLayer(self, layerName, fileName)

Sets the layerName's log feature.

logMsg(self, layerName, message)

Logs a message with layerName log.

mapInput(self, layerName, offset=0)

Adds layerName and offset to inputMap.

mapTarget(self, layerName, offset=0)

Adds layerName and offset to targetMap.

path(self, startLayer, endLayer)

Used in error checking with verifyArchitecture() and in prop_from().

patternVector(self, vector)

Replaces vector with patterns. Used for loading inputs or
targets from a file and still preserving patterns.

prop_from(self, startLayers)

Start propagation from the layers in the list
startLayers. Make sure startLayers are initialized with the
desired activations. NO ERROR CHECKING.

propagate(self, **args)

Propagates activation through the network. Optionally, takes input layer names
as keywords, and their associated activations. If input layer(s) are given, then
propagate() will return the output layer's activation. If there is more than
one output layer, then a dictionary is returned.

Examples:

>>> net.propagate()
>>> net.propagate(input = [0, .5, 0], context = [.5, .5, .5])
{"output": [0.345]}

propagateFrom(self, startLayer, **args)

Propagates activation through the network. Optionally, takes input layer names
as keywords, and their associated activations. If input layer(s) are given, then
propagate() will return the output layer's activation. If there is more than
one output layer, then a dictionary is returned.

Examples:

>>> net.propagate()
>>> net.propagate(input = [0, .5, 0], context = [.5, .5, .5])
{"output": [0.345]}

putActivations(self, dict)

Puts a dict of name: activations into their respective layers.

randomizeOrder(self)

Randomizes self.loadOrder, the order in which inputs set with
self.setInputs() are presented.

replacePatterns(self, vector)

Replaces patterned inputs or targets with activation vectors.

reset(self)

Resets seed values.

resetFlags(self)

Resets layer flags for activation and target.

RMSError(self)

Returns Root Mean Squared Error for all output layers in this network.

saveDataToFile(self, filename)

Saves data (targets/inputs) to file.

saveInputsToFile(self, filename)

Saves inputs to file.

saveNetworkToFile(self, filename, makeWrapper=1)

Saves network to file using pickle.

saveTargetsToFile(self, filename)

Saves targets to file.

saveWeightsToFile(self, filename, mode='pickle')

Saves weights to file in pickle, plain, or tlearn mode.

setActive(self, layerName, value)

Sets a layer to active. Affects ce_init(), compute_error(),
propagate(), change_weights(), display().

setBatch(self, value)

Sets self.batch to value. Accumulates error over the entire
training set and only changes weights after each training
batch is complete.

setEpsilon(self, value)

Sets epsilon value for the network.

setInputs(self, inputs)

Sets self.input to inputs. Load order is by default random. Use setOrderedInputs() to order inputs.

setInputsAndTargets(self, data1, data2=None)

Network.setInputsAndTargets()
Sets the corpus of data for training. Can be in one of two formats:

Format 1: setInputsAndTargets([[input0, target0], [input1, target1]...])
Network.setInputsAndTargets([[[i00, i01, ...], [t00, t01, ...]],
                             [[i10, i11, ...], [t10, t11, ...]],
                             ...])
Format 2: setInputsAndTargets([input0, input1, ...], [target0, target1, ...])
Network.setInputsAndTargets([[i00, i01, ...], [i10, i11, ...],...],
                            [[t00, t01, ...], [t10, t11, ...],...] )

setInteractive(self, value)

Sets interactive to value. Specifies if an interactive prompt
should accompany sweep() or step().

setLearning(self, value)

Sets learning to value. Determines if the network learns,
ie. changes connection weights.

setMaxRandom(self, value)

Sets the maxRandom Layer attribute for each layer to value.Specifies
the global range for randomly initialized values, [-max, max].

setMomentum(self, value)

Sets self.momentum to value. Used in change_weights().

setOrderedInputs(self, value)

Sets self.orderedInputs to value. Specifies if inputs
should be ordered and if so orders the inputs.

setOutputs(self, outputs)

For compatiblity.

setPattern(self, word, vector)

Sets a pattern with key word. Better to use addPattern() and
delPattern().

Example: net.setPattern("tom", [1, 0, 0, 0])

setPatterned(self, value)

Sets the network to use patterns for inputs and targets.

setPatterns(self, patterns)

Sets patterns to the dictionary argument.

Example: net.setPatterns( {"tom": [0, 0, 0, 1], "mary": [1, 0, 0, 0]} )

Sets net.patterned to 1 as a side-effect.

setReportRate(self, value)

Sets self.reportRate to value.  train() will report when
epoch % reportRate == 0. Cross validation will only report if
there is a cross validation data set.

setResetEpoch(self, value)

Sets self.resetEpoch to value. When the number of epochs
reaches self.resetEpoch the network restarts.

setResetLimit(self, value)

Sets self.resetLimit to value. When the number of resets
reaches the reset limit the network quits.

setSeed(self, value)

Sets the seed to value.

setSigmoid_prime_offset(self, value)

Sets self.sigmoid_prime_offset to value.

setStopPercent(self, value)

Sets self.stopPercent to value. train() will stop if the percent
correct surpasses the stop percent.

setSweepReportRate(self, value)

Sets self.sweepReportRate to value.  sweep() will report
when epoch % sweepReportRate == 0.  there is a cross
validation data set.

setTargets(self, targets)

Sets the targets.

setTolerance(self, value)

Sets tolerance to value. This specifies how close acceptable
outputs must be to targets.

setUseCrossValidationToStop(self, value)

Sets flag so that self.stopPercent is compared to cross validation
percent rather than the regular training data percentage correct.

setVerbosity(self, value)

Sets self.verbosity and each layer verbosity to value.

setWeight(self, fromName, fromPos, toName, toPos, value)

Sets the weight of the connection between two layers (argument strings).

shareWeights(self, network, listOfLayerNamePairs=None)

Share weights with another network. Connection
is broken after a randomize or change of size. Layers must have the same
names and sizes for shared connections in both networks.

Example: net.shareWeights(otherNet, [["hidden", "output"]])

This example will take the weights between the hidden and output layers
of otherNet and share them with net. Also, the bias values of
otherNet["output"] will be shared with net["output"].

If no list is given, will share all weights.

step(self, **args)

Network.step()
Does a single step. Calls propagate(), backprop(), and
change_weights() if learning is set.
Format for parameters: <layer name> = <activation/target list>

sweep(self)

Runs through entire dataset. 
Returns TSS error, total correct, and total count.

sweepCrossValidation(self)

sweepCrossValidation() will go through each of the crossvalidation input/targets.
The crossValidationCorpus is a list of dictionaries of input/targets
referenced by layername.
Example: ({"input": [0.0, 0.1], "output": [1.0]}, {"input": [0.5, 0.9], "output": [0.0]})

toString(self)

Returns the network layers as a string.

train(self, cont=0)

Trains the network on the dataset till a stopping condition is
met. This stopping condition can be a limiting epoch or a percentage correct requirement.

TSSError(self, layerName)

Returns Total Sum Squared error for the specified layer's pattern.

unArrayify(self, gene)

Copies gene bias values and weights to network bias values and
weights.

verifyArchitecture(self)

Check for orphaned layers or connections. Assure that network
architecture is feed-forward (no-cycles). Check connectivity. Check naming.

verifyArguments(self, arg)

Verifies that arguments to setInputs and setTargets are appropriately formatted.

verifyInputs(self)

Used in propagate() to verify that the network input
activations have been set.

verifyTargets(self)

Used in backprop() to verify that the network targets have
been set.

Generated by Epydoc 2.1 on Mon Jul 25 01:39:27 2005 http://epydoc.sf.net