org.encog.neural.networks.layers
Class BasicLayer

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

public class BasicLayer
extends Object
implements Layer, 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 following summarizes how basic layers calculate the output for a neural network. Example of a simple XOR network. Input: BasicLayer: 2 Neurons, null biasWeights, null biasActivation Hidden: BasicLayer: 2 Neurons, 2 biasWeights, 1 biasActivation Output: BasicLayer: 1 Neuron, 1 biasWeights, 1 biasActivation Input1Output and Input2Output are both provided. Synapse 1: Input to Hidden Hidden1Activation = (Input1Output * Input1->Hidden1Weight) + (Input2Output * Input2->Hidden1Weight) + (HiddenBiasActivation * Hidden1BiasWeight) Hidden1Output = calculate(Hidden1Activation, HiddenActivationFunction) Hidden2Activation = (Input1Output * Input1->Hidden2Weight) + (Input2Output * Input2->Hidden2Weight) + (HiddenBiasActivation * Hidden2BiasWeight) Hidden2Output = calculate(Hidden2Activation, HiddenActivationFunction) Synapse 2: Hidden to Output Output1Activation = (Hidden1Output * Hidden1->Output1Weight) + (Hidden2Output * Hidden2->Output1Weight) + (OutputBiasActivation * Output1BiasWeight) Output1Output = calculate(Output1Activation, OutputActivationFunction)

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 hasBias, int neuronCount)
          Construct this layer with a non-default activation function, also determine if a bias is desired or not.
BasicLayer(int neuronCount)
          Construct this layer with a sigmoid activation 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.
 int compareTo(Layer other)
          
 NeuralData compute(NeuralData pattern)
          Compute the outputs for this layer given the input pattern.
 Persistor createPersistor()
          Create a persistor for this layer.
 ActivationFunction getActivationFunction()
           
 double getBiasActivation()
          Most layer types will default this value to one.
 double getBiasWeight(int index)
          Get an bias weight value.
 double[] getBiasWeights()
           
 EncogCollection getCollection()
           
 String getDescription()
           
 int getID()
           
 String getName()
           
 BasicNetwork getNetwork()
           
 int getNeuronCount()
          Get the neuron count for this layer.
 List<Synapse> getNext()
          Get a list of all of the outbound synapse connections from this layer.
 Collection<Layer> getNextLayers()
           
 int getX()
           
 int getY()
           
 boolean hasBias()
           
 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 setBiasActivation(double activation)
          Set the bias activation.
 void setBiasWeight(int index, double d)
          Set an individual bias weight value.
 void setBiasWeights(double[] d)
          Set the bias array.
 void setCollection(EncogCollection collection)
          Not used, layers do not belong to collections.
 void setDescription(String description)
          Set the description of this object.
 void setID(int id)
          Set the id for this layer.
 void setName(String name)
          Set the name of this object.
 void setNetwork(BasicNetwork network)
          Set the network for this layer.
 void setNeuronCount(int neuronCount)
          Set the neuron count.
 void setX(int x)
          Set the x coordinate for this layer.
 void setY(int y)
          Set the y coordinate for this layer.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, 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 hasBias,
                  int neuronCount)
Construct this layer with a non-default activation function, also determine if a bias is desired or not.

Parameters:
activationFunction - The activation function to use.
neuronCount - How many neurons in this layer.
hasBias - True if this layer has a bias.

BasicLayer

public BasicLayer(int neuronCount)
Construct this layer with a sigmoid activation 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.

compareTo

public int compareTo(Layer other)

Specified by:
compareTo in interface Comparable<Layer>

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 String getDescription()
Specified by:
getDescription in interface EncogPersistedObject
Returns:
the description

getID

public int getID()
Specified by:
getID in interface Layer
Returns:
The id of this layer.

getName

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

getNetwork

public BasicNetwork getNetwork()
Specified by:
getNetwork in interface Layer
Returns:
The network that owns this layer.

getNeuronCount

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

Specified by:
getNeuronCount in interface Layer
Returns:
the neuronCount

getNext

public 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 Collection<Layer> getNextLayers()
Specified by:
getNextLayers in interface Layer
Returns:
The list of layers that the outbound synapses connect to.

getBiasWeights

public double[] getBiasWeights()
Specified by:
getBiasWeights in interface Layer
Returns:
The bias weight values.

getBiasWeight

public double getBiasWeight(int index)
Get an bias weight value. See the Layer interface documentation for more information on how Encog handles bias values.

Specified by:
getBiasWeight in interface Layer
Parameters:
index - The bias value to get.
Returns:
The bias 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.

hasBias

public boolean hasBias()
Specified by:
hasBias in interface Layer
Returns:
True if a bias is 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(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

setID

public void setID(int id)
Set the id for this layer.

Specified by:
setID in interface Layer
Parameters:
id - The id for this layer.

setName

public void setName(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

setNetwork

public void setNetwork(BasicNetwork network)
Set the network for this layer.

Specified by:
setNetwork in interface Layer
Parameters:
network - The network for this layer.

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.

setBiasWeights

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

Specified by:
setBiasWeights in interface Layer
Parameters:
d - The new bias weight array.

setBiasWeight

public void setBiasWeight(int index,
                          double d)
Set an individual bias weight value.

Specified by:
setBiasWeight in interface Layer
Parameters:
index - The index of the bias weight value.
d - The new bias weight value.

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 String toString()

Overrides:
toString in class Object

getBiasActivation

public double getBiasActivation()
Description copied from interface: Layer
Most layer types will default this value to one. However, it is possible to use other values. This is the activation that will be passed over the bias weights to the inputs of this layer. See the Layer interface documentation for more information on how Encog handles bias values.

Specified by:
getBiasActivation in interface Layer
Returns:
The bias activation, usually 1. See Layer for more info.

setBiasActivation

public void setBiasActivation(double activation)
Set the bias activation. Generally 1, see Layer for more info.

Specified by:
setBiasActivation in interface Layer
Parameters:
activation - The activation.

getCollection

public EncogCollection getCollection()
Specified by:
getCollection in interface EncogPersistedObject
Returns:
Returns null, layers do not belong to collections.

setCollection

public void setCollection(EncogCollection collection)
Not used, layers do not belong to collections.

Specified by:
setCollection in interface EncogPersistedObject
Parameters:
collection - Not used.


Copyright © 2011. All Rights Reserved.