com.penguinwerks.jodene
Class Network

java.lang.Object
  extended bycom.penguinwerks.jodene.Network
All Implemented Interfaces:
java.io.Serializable

public class Network
extends java.lang.Object
implements java.io.Serializable

This is a neural network. It is composed of neurons, some of which are input neurons, some of which are output neurons, and some are internal (hidden layer) neurons.

A network does not automatically connect neurons, except for the bias neuron. When the network is created, the neurons are connected by using the connect method.

Note that the neuron receives its input and produces its output as a java.util.Map. The map is keyed on the name of the input. The key in the input must match the name of the input neuron, otherwise an exception is thrown. See the com.penguinwerks.black.data package for utilities to read in data as a named map.

Author:
Paul Hoehne
See Also:
Serialized Form

Constructor Summary
Network()
          Create a new instance of a network.
 
Method Summary
 void addInputNeuron(Neuron neuron)
          Add input neuron.
 void addInternalNeuron(Neuron neuron)
          Adds a "hidden layer" neuron.
 void addOutputNeuron(Neuron neuron)
          Add output neuron.
 void adjustWeights()
          Called during training to periodically adjust the weights on the network.
 void beginTraining(Trainer trainer)
          Attaches a trainer to the network and establishes any necessary structures for training.
 void connect(Neuron base, Neuron dendrite)
          Connect two neurons.
 void connect(java.lang.String base, java.lang.String dendrite)
          Connect two nuerons by their name.
 void endTraining()
          Completes the training by removing training structures from the network.
 ActivationFactory getActivationFactory()
          Returns the activaiton factory.
 NeuronTraining getTrainer(java.lang.String neuronId)
          Returns the trainer attached to this network.
 java.util.Map process(java.util.Map inputs)
          Process a set of inputs and return a result.
 void setActivationFactory(ActivationFactory factory)
          Set the activation factory which will create new activation functions.
 void setFeedback(java.util.Map actual, java.util.Map expected)
          During training a network is presented the actual and expected values for a given input.
 void updateAdjustments()
          Updates the weight adjustments for all the neurons in the network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Network

public Network()
Create a new instance of a network. By default a bias node is added to the network and automatically connected to any neurons added to the network (except input neurons).

Method Detail

setActivationFactory

public void setActivationFactory(ActivationFactory factory)
Set the activation factory which will create new activation functions.

Parameters:
factory - The activation factory.

getActivationFactory

public ActivationFactory getActivationFactory()
Returns the activaiton factory.

Returns:
The activation factory.

addOutputNeuron

public void addOutputNeuron(Neuron neuron)
                     throws DuplicateNeuronException
Add output neuron.

Parameters:
neuron - The output neuron.
Throws:
DuplicateNeuronException - Thrown if a neuron with the same name exists.

addInputNeuron

public void addInputNeuron(Neuron neuron)
                    throws DuplicateNeuronException
Add input neuron. Input neurons have their value "set" to a given value and then propagate that value to any neurons they are connected to.

Parameters:
neuron - The new input neuron.
Throws:
DuplicateNeuronException - Thrown if a neuron with the same name already exists.

addInternalNeuron

public void addInternalNeuron(Neuron neuron)
                       throws DuplicateNeuronException
Adds a "hidden layer" neuron. Hidden layers get their inputs from either input neurons or other hidden layers. They then pass those values to the next output or hidden layer.

Parameters:
neuron - The new neuron to add
Throws:
DuplicateNeuronException - Thrown if a neuron with the same name exists.

connect

public void connect(java.lang.String base,
                    java.lang.String dendrite)
Connect two nuerons by their name. This method is used to build up connections within the network. The only connection established by default is the connection to the bias node. This is the preferred method.

Parameters:
base - The name of the base neuron to connect.
dendrite - The name of the dendrite neuron to connect.

connect

public void connect(Neuron base,
                    Neuron dendrite)
Connect two neurons. This method is used to build up connections within the network. The only connection established by default is the connection to the bias node.

Parameters:
base - A base neuron to connect.
dendrite - A dendrite neuron to connect.

process

public java.util.Map process(java.util.Map inputs)
                      throws InvalidInputsException
Process a set of inputs and return a result. The method checks to see that the names in the input map correspond to the names of the input neurons. If they do not match, an InvalidInputsException is thrown. It returns a map with the output values keyed on the names of the output neurons.

Parameters:
inputs - The inputs to the network
Returns:
The processed result;
Throws:
InvalidInputsException - Thrown if the input names do not match the input neuron names.

getTrainer

public NeuronTraining getTrainer(java.lang.String neuronId)
Returns the trainer attached to this network. A trainer configures the network for training on a given method or algorithm.

Parameters:
neuronId - Returns the neuron trainer for the named neuron.
Returns:
The neuron trainer used by a given neuron.

setFeedback

public void setFeedback(java.util.Map actual,
                        java.util.Map expected)
During training a network is presented the actual and expected values for a given input. Based on this, the network back-propagates the errors and by the derivative chaining rule, calculates the weight adjustments necessary to train the network, given the trainer.

Parameters:
actual - The actual values obtained from executing the network.
expected - The expected values from a training example.

beginTraining

public void beginTraining(Trainer trainer)
Attaches a trainer to the network and establishes any necessary structures for training.

Parameters:
trainer - The trainer that will perform the training.

endTraining

public void endTraining()
Completes the training by removing training structures from the network.


adjustWeights

public void adjustWeights()
Called during training to periodically adjust the weights on the network.


updateAdjustments

public void updateAdjustments()
Updates the weight adjustments for all the neurons in the network. Note that this is not the same as updating the weights. This just calculates the change in the weight.