The Encog Project

org.encog.neural.networks.layers
Class BasicLayer

java.lang.Object
  extended by org.encog.neural.networks.layers.BasicLayer
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Layer, EncogPersistedObject
Direct Known Subclasses:
ContextLayer, RadialBasisFunctionLayer

public class BasicLayer
extends java.lang.Object
implements Layer, java.io.Serializable

Basic functionality that most of the neural layers require. The basic layer is often used by itself to implement forward or recurrent layers. Other layer types are based on the basic layer as well. The layer will either have thresholds are not. Thresholds are values that correspond to each of the neurons. The threshold values will be added to the output calculated for each neuron. Together with the weight matrix the threshold values make up the memory of the neural network. When the neural network is trained, these threshold values (along with the weight matrix values) will be modified.

Author:
jheaton
See Also:
Serialized Form

Constructor Summary
BasicLayer()
          Default constructor, mainly so the workbench can easily create a default layer.
BasicLayer(ActivationFunction activationFunction, boolean hasThreshold, int neuronCount)
          Construct this layer with a non-default threshold function.
BasicLayer(int neuronCount)
          Construct this layer with a sigmoid threshold function.
 
Method Summary
 void addNext(Layer next)
          Add a layer as the next layer.
 void addNext(Layer next, SynapseType type)
          Add a layer to this layer.
 void addSynapse(Synapse synapse)
          Add a synapse to the list of outbound synapses.
 java.lang.Object clone()
          Clone this object.
 NeuralData compute(NeuralData pattern)
          Compute the outputs for this layer given the input pattern.
 Persistor createPersistor()
          Create a persistor for this layer.
 ActivationFunction getActivationFunction()
           
 java.lang.String getDescription()
           
 java.lang.String getName()
           
 int getNeuronCount()
          Get the neuron count for this layer.
 java.util.List<Synapse> getNext()
          Get a list of all of the outbound synapse connections from this layer.
 java.util.Collection<Layer> getNextLayers()
           
 double[] getThreshold()
           
 double getThreshold(int index)
          Get an individual threshold value.
 int getX()
           
 int getY()
           
 boolean hasThreshold()
           
 boolean isConnectedTo(Layer layer)
          Determine if this layer is connected to another layer.
 boolean isSelfConnected()
           
 void process(NeuralData pattern)
          Process the input pattern.
 NeuralData recur()
          Get the output from this layer when called in a recurrent manor.
 void setActivationFunction(ActivationFunction f)
          Set the activation function for this layer.
 void setDescription(java.lang.String description)
          Set the description of this object.
 void setName(java.lang.String name)
          Set the name of this object.
 void setNeuronCount(int neuronCount)
          Set the neuron count.
 void setThreshold(double[] d)
          Set the threshold array.
 void setThreshold(int index, double d)
          Set the specified threshold value.
 void setX(int x)
          Set the x coordinate for this layer.
 void setY(int y)
          Set the y coordinate for this layer.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicLayer

public BasicLayer()
Default constructor, mainly so the workbench can easily create a default layer.


BasicLayer

public BasicLayer(ActivationFunction activationFunction,
                  boolean hasThreshold,
                  int neuronCount)
Construct this layer with a non-default threshold function.

Parameters:
activationFunction - The threshold function to use.
neuronCount - How many neurons in this layer.
hasThreshold - True if this layer has threshold values.

BasicLayer

public BasicLayer(int neuronCount)
Construct this layer with a sigmoid threshold function.

Parameters:
neuronCount - How many neurons in this layer.
Method Detail

addNext

public void addNext(Layer next)
Add a layer as the next layer. The layer will be added with a weighted synapse.

Specified by:
addNext in interface Layer
Parameters:
next - THe next layer.

addNext

public void addNext(Layer next,
                    SynapseType type)
Description copied from interface: Layer
Add a layer to this layer. The "next" layer being added will receive input from this layer. You can also add a layer to itself, this will create a self-connected layer.

Specified by:
addNext in interface Layer
Parameters:
next - The next layer to add.
type - The synapse type to use for this layer.

addSynapse

public void addSynapse(Synapse synapse)
Add a synapse to the list of outbound synapses. Usually you should simply call the addLayer method to add to the outbound list.

Specified by:
addSynapse in interface Layer
Parameters:
synapse - The synapse to add.

clone

public java.lang.Object clone()
Clone this object.

Specified by:
clone in interface Layer
Specified by:
clone in interface EncogPersistedObject
Overrides:
clone in class java.lang.Object
Returns:
A cloned version of this object.

compute

public NeuralData compute(NeuralData pattern)
Compute the outputs for this layer given the input pattern. The output is also stored in the fire instance variable.

Specified by:
compute in interface Layer
Parameters:
pattern - The input pattern.
Returns:
The output from this layer.

createPersistor

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

Specified by:
createPersistor in interface EncogPersistedObject
Returns:
The new persistor.

getActivationFunction

public ActivationFunction getActivationFunction()
Specified by:
getActivationFunction in interface Layer
Returns:
The activation function for this layer.

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface EncogPersistedObject
Returns:
the description

getName

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

getNeuronCount

public int getNeuronCount()
Get the neuron count for this layer.

Specified by:
getNeuronCount in interface Layer
Returns:
the neuronCount

getNext

public java.util.List<Synapse> getNext()
Description copied from interface: Layer
Get a list of all of the outbound synapse connections from this layer.

Specified by:
getNext in interface Layer
Returns:
The outbound synapse connections.

getNextLayers

public java.util.Collection<Layer> getNextLayers()
Specified by:
getNextLayers in interface Layer
Returns:
The list of layers that the outbound synapses connect to.

getThreshold

public double[] getThreshold()
Specified by:
getThreshold in interface Layer
Returns:
The threshold values.

getThreshold

public double getThreshold(int index)
Get an individual threshold value.

Specified by:
getThreshold in interface Layer
Parameters:
index - The threshold value to get.
Returns:
The threshold value.

getX

public int getX()
Specified by:
getX in interface Layer
Returns:
The x-coordinate. Used when the layer is displayed in a GUI.

getY

public int getY()
Specified by:
getY in interface Layer
Returns:
The y-coordinate. Used when the layer is displayed in a GUI.

hasThreshold

public boolean hasThreshold()
Specified by:
hasThreshold in interface Layer
Returns:
True if threshold values are present.

isConnectedTo

public boolean isConnectedTo(Layer layer)
Determine if this layer is connected to another layer.

Specified by:
isConnectedTo in interface Layer
Parameters:
layer - A layer to check and see if this layer is connected to.
Returns:
True if the two layers are connected.

isSelfConnected

public boolean isSelfConnected()
Returns:
True if this layer is connected to intself.

process

public void process(NeuralData pattern)
Process the input pattern. For the basic layer, nothing is done. This is how the context layer gets a chance to record the input. Other similar functions, where access is needed to the input.

Specified by:
process in interface Layer
Parameters:
pattern - The input to this layer.

recur

public NeuralData recur()
Get the output from this layer when called in a recurrent manor. For the BaiscLayer, this is not implemented.

Specified by:
recur in interface Layer
Returns:
The output when called in a recurrent way.

setActivationFunction

public void setActivationFunction(ActivationFunction f)
Set the activation function for this layer.

Specified by:
setActivationFunction in interface Layer
Parameters:
f - The activation function.

setDescription

public void setDescription(java.lang.String description)
Description copied from interface: EncogPersistedObject
Set the description of this object.

Specified by:
setDescription in interface EncogPersistedObject
Parameters:
description - the description to set

setName

public void setName(java.lang.String name)
Description copied from interface: EncogPersistedObject
Set the name of this object.

Specified by:
setName in interface EncogPersistedObject
Parameters:
name - the name to set

setNeuronCount

public void setNeuronCount(int neuronCount)
Set the neuron count. This just sets it, it does not make any adjustments to the class. To automatically change the neuron count refer to the pruning classes.

Specified by:
setNeuronCount in interface Layer
Parameters:
neuronCount - The new neuron count.

setThreshold

public void setThreshold(double[] d)
Set the threshold array. This does not modify any of the other values in the network, it just sets the threshold array. If you want to change the structure of the neural network you should use the pruning classes.

Specified by:
setThreshold in interface Layer
Parameters:
d - The new threshold array.

setThreshold

public void setThreshold(int index,
                         double d)
Set the specified threshold value.

Specified by:
setThreshold in interface Layer
Parameters:
index - The threshold value to set.
d - The value to set the threshold to.

setX

public void setX(int x)
Set the x coordinate for this layer. The coordinates are used when the layer must be displayed in a GUI situation.

Specified by:
setX in interface Layer
Parameters:
x - The x-coordinate.

setY

public void setY(int y)
Set the y coordinate for this layer. The coordinates are used when the layer must be displayed in a GUI situation.

Specified by:
setY in interface Layer
Parameters:
y - The y-coordinate.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
This object as a string.

The Encog Project