The Encog Project

org.encog.neural.networks
Class BasicNetwork

java.lang.Object
  extended by org.encog.neural.networks.BasicNetwork
All Implemented Interfaces:
java.io.Serializable, Network, EncogPersistedObject

public class BasicNetwork
extends java.lang.Object
implements java.io.Serializable, Network, EncogPersistedObject

BasicNetwork: This class implements a neural network. This class works in conjunction the Layer classes. Layers are added to the BasicNetwork to specify the structure of the neural network. The first layer added is the input layer, the final layer added is the output layer. Any layers added between these two layers are the hidden layers.

See Also:
Serialized Form

Constructor Summary
BasicNetwork()
          Construct an empty neural network.
 
Method Summary
 void addLayer(Layer layer)
          Add a layer to the neural network.
 void addLayer(Layer baseLayer, Layer newLayer)
          Add a layer after the base layer.
 double calculateError(NeuralDataSet data)
          Calculate the error for this neural network.
 int calculateNeuronCount()
          Calculate the total number of neurons in the network across all layers.
 java.lang.Object clone()
          Return a clone of this neural network.
 BasicNetwork cloneStructure()
          Return a clone of the structure of this neural network.
 NeuralData compute(NeuralData input)
          Compute the output for a given input to the neural network.
 Persistor createPersistor()
          Create a persistor for this object.
 boolean equals(BasicNetwork other)
          Compare the two neural networks.
 java.lang.String getDescription()
           
 int getHiddenLayerCount()
          Get the count for how many hidden layers are present.
 java.util.Collection<Layer> getHiddenLayers()
          Get a collection of the hidden layers in the network.
 Layer getInputLayer()
          Get the input layer.
 java.util.List<Layer> getLayers()
          Get all layers.
 java.lang.String getName()
           
 Layer getOutputLayer()
          Get the output layer.
 int getWeightMatrixSize()
          Get the size of the weight and threshold matrix.
 int hashCode()
          Generate a hash code.
 void removeLayer(Layer layer)
          Remove a layer, adjust the weight matrixes and back pointers.
 void reset()
          Reset the weight matrix and the thresholds.
 void setDescription(java.lang.String theDescription)
          Set the description for this object.
 void setName(java.lang.String name)
           
 int winner(NeuralData input)
          Determine the winner for the specified input.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicNetwork

public BasicNetwork()
Construct an empty neural network.

Method Detail

addLayer

public void addLayer(Layer layer)
Add a layer to the neural network. The first layer added is the input layer, the last layer added is the output layer.

Parameters:
layer - The layer to be added.

addLayer

public void addLayer(Layer baseLayer,
                     Layer newLayer)
Add a layer after the base layer.

Parameters:
baseLayer - The layer to add after.
newLayer - The new layer to add.

calculateError

public double calculateError(NeuralDataSet data)
Calculate the error for this neural network. The error is calculated using root-mean-square(RMS).

Parameters:
data - The training set.
Returns:
The error percentage.

calculateNeuronCount

public int calculateNeuronCount()
Calculate the total number of neurons in the network across all layers.

Returns:
The neuron count.

clone

public java.lang.Object clone()
Return a clone of this neural network. Including structure, weights and threshold values.

Overrides:
clone in class java.lang.Object
Returns:
A cloned copy of the neural network.

cloneStructure

public BasicNetwork cloneStructure()
Return a clone of the structure of this neural network.

Returns:
A cloned copy of the structure of the neural network.

compute

public NeuralData compute(NeuralData input)
Compute the output for a given input to the neural network.

Specified by:
compute in interface Network
Parameters:
input - The input provide to the neural network.
Returns:
The results from the output neurons.

createPersistor

public Persistor createPersistor()
Create a persistor for this object.

Specified by:
createPersistor in interface EncogPersistedObject
Returns:
The newly created persistor.

equals

public boolean equals(BasicNetwork other)
Compare the two neural networks. For them to be equal they must be of the same structure, and have the same matrix values.

Parameters:
other - The other neural network.
Returns:
True if the two networks are equal.

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface EncogPersistedObject
Returns:
The description for this object.

getHiddenLayerCount

public int getHiddenLayerCount()
Get the count for how many hidden layers are present.

Returns:
The hidden layer count.

getHiddenLayers

public java.util.Collection<Layer> getHiddenLayers()
Get a collection of the hidden layers in the network.

Returns:
The hidden layers.

getInputLayer

public Layer getInputLayer()
Get the input layer.

Returns:
The input layer.

getLayers

public java.util.List<Layer> getLayers()
Get all layers.

Returns:
All layers.

getName

public java.lang.String getName()
Specified by:
getName in interface EncogPersistedObject
Returns:
the name

getOutputLayer

public Layer getOutputLayer()
Get the output layer.

Returns:
The output layer.

getWeightMatrixSize

public int getWeightMatrixSize()
Get the size of the weight and threshold matrix.

Returns:
The size of the matrix.

hashCode

public int hashCode()
Generate a hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
THe hash code.

removeLayer

public void removeLayer(Layer layer)
Remove a layer, adjust the weight matrixes and back pointers.

Parameters:
layer - The layer to remove.

reset

public void reset()
Reset the weight matrix and the thresholds.

Throws:
MatrixException

setDescription

public void setDescription(java.lang.String theDescription)
Set the description for this object.

Specified by:
setDescription in interface EncogPersistedObject
Parameters:
theDescription - The description.

setName

public void setName(java.lang.String name)
Specified by:
setName in interface EncogPersistedObject
Parameters:
name - the name to set

winner

public int winner(NeuralData input)
Determine the winner for the specified input. This is the number of the winning neuron.

Parameters:
input - The input patter to present to the neural network.
Returns:
The winning neuron.

The Encog Project