de.htwdd.rosenkoenig.neuro.net
Class FeedForwardNet

java.lang.Object
  extended by de.htwdd.rosenkoenig.neuro.net.NeuralNet
      extended by de.htwdd.rosenkoenig.neuro.net.FeedForwardNet

public class FeedForwardNet
extends NeuralNet

This class implements a feed forward net. The code and the functionality might be a little abstruse sometimes. This is to improve the performance of the net in 99% of the case and laziness of the one who implemented it in 1% of the cases.


Field Summary
private static java.lang.Class[] CONSTRUCTOR_PARAMS
           
private  boolean initialized
          Determines the initialization state of the net.
private  InputLayer inputLayer
          The input layer of the net.
private  java.util.ArrayList<InnerLayer> layers
          This is the ArrayList representation of the hidden layers and the output layer.
 
Constructor Summary
FeedForwardNet()
          Creates an empty FeedForwardNet (i.e. without any layers).
FeedForwardNet(int inputLayerSize, int outputLayerSize)
          Creates a FeedForwardNet with inputLayerSize number of input layers and outputLayerSize number of output layers.
 
Method Summary
 void addHiddenLayer(int layerSize, ActivationFunction activationFunction)
          Add a hidden layer of layerSize using activationFunction to your net.
 boolean addLayers(InnerLayer innerLayer)
          Appends the specified layer to the end of this list (optional operation).
 void addLayers(int index, InnerLayer innerLayer)
          Inserts the specified layer at the specified position in this list (optional operation)
 void clearLayers()
          Removes all of the layers from this list (optional operation).
private  void connectLayers()
          This function takes this net and connects all layers.
 boolean containsAllLayers(java.util.Collection<InnerLayer> layers)
          Returns true if this list contains all of the layers of the specified collection.
 boolean containsLayers(InnerLayer innerLayer)
          Returns true if this list contains the specified layer.
 org.jdom.Element createXml()
          Forge the net into xml.
 void extractNet(org.jdom.Element xmlNet)
          This is the couterpart function of de.htwdd.rosenkoenig.neuro.net.createXml.
 boolean getInitialized()
          Getter of the property initialized
 InputLayer getInputLayer()
          Getter of the property inputLayer
 java.util.ArrayList<InnerLayer> getLayers()
          Getter of the property layers
 InnerLayer getLayers(int i)
          Returns the layer at the specified position in this list.
 double[] getOutput()
          This function returns the member output of the last layer, which is the output layer.
 void initForTraining()
          This function initializes the net for the training.
 boolean isLayersEmpty()
          Returns true if this list contains no layers.
 java.util.Iterator<InnerLayer> layersIterator()
          Returns an iterator over the layers in this list in proper sequence.
 int layersSize()
          Returns the number of layers in this list.
 InnerLayer[] layersToArray()
          Returns an array containing all of the layers in this list in proper sequence.
 InnerLayer[] layersToArray(InnerLayer[] layers)
          Returns an array containing all of the layers in this list in proper sequence; the runtime type of the returned array is that of the specified array.
 void propagate(double[] pattern)
          Fully connects the net's layers, if the net is not initialized and propagate the pattern given by pattern through all layers.
 boolean removeLayers(InnerLayer innerLayer)
          Removes the first occurrence in this list of the specified layer (optional operation).
 java.lang.Object removeLayers(int index)
          Removes the layer at the specified position in this list (optional operation).
 void setInitialized(boolean initialized)
          Setter of the property initialized
 void setInputLayer(InputLayer inputLayer)
          Setter of the property inputLayer
 void setLayers(java.util.ArrayList<InnerLayer> layers)
          Setter of the property layers
 
Methods inherited from class de.htwdd.rosenkoenig.neuro.net.NeuralNet
loadFromFile, saveToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTRUCTOR_PARAMS

private static final java.lang.Class[] CONSTRUCTOR_PARAMS

initialized

private boolean initialized
Determines the initialization state of the net. The value changes when you add new layers (becomes false) and when you connect the layers of the net.


inputLayer

private InputLayer inputLayer
The input layer of the net.


layers

private java.util.ArrayList<InnerLayer> layers
This is the ArrayList representation of the hidden layers and the output layer.

Constructor Detail

FeedForwardNet

public FeedForwardNet()
Creates an empty FeedForwardNet (i.e. without any layers).


FeedForwardNet

public FeedForwardNet(int inputLayerSize,
                      int outputLayerSize)
Creates a FeedForwardNet with inputLayerSize number of input layers and outputLayerSize number of output layers. Hidden layers are not created here use de.htwdd.rosenkoenig.neuro.net.addHiddenLayer to add hidden layers to the net

Parameters:
inputLayerSize - number of neurons for the input layer
outputLayerSize - number of neurons for the output layer
Method Detail

addHiddenLayer

public void addHiddenLayer(int layerSize,
                           ActivationFunction activationFunction)
Add a hidden layer of layerSize using activationFunction to your net. The newly created layer will be added as the last layer before the output layer.

Parameters:
layerSize - size of the newly added hidden layer
activationFunction - activation function to be used

propagate

public final void propagate(double[] pattern)
Fully connects the net's layers, if the net is not initialized and propagate the pattern given by pattern through all layers.

Specified by:
propagate in class NeuralNet
Parameters:
pattern - the input pattern to propagate

connectLayers

private void connectLayers()
This function takes this net and connects all layers. Having done so, it sets initialized to true. The object used to connect all layers is a Synapse. it is not straightforward to connect all neurons using only one synapse, but it serves the purpose of speeding up the implementation.


getOutput

public double[] getOutput()
This function returns the member output of the last layer, which is the output layer.

Specified by:
getOutput in class NeuralNet
Returns:
the output of the output layer

createXml

public org.jdom.Element createXml()
Forge the net into xml.

Specified by:
createXml in class NeuralNet
Returns:
the xml representation of the net

extractNet

public void extractNet(org.jdom.Element xmlNet)
This is the couterpart function of de.htwdd.rosenkoenig.neuro.net.createXml. It takes the xml representation of a net and converts it back into a net

Specified by:
extractNet in class NeuralNet
Parameters:
xmlNet - the net's xml representation to be molded into a feed forward net

getInitialized

public boolean getInitialized()
Getter of the property initialized

Returns:
Returns the initialized.

setInitialized

public void setInitialized(boolean initialized)
Setter of the property initialized

Parameters:
initialized - The initialized to set.

initForTraining

public final void initForTraining()
This function initializes the net for the training. This means connecting all layers and initializing the layers.


getInputLayer

public InputLayer getInputLayer()
Getter of the property inputLayer

Returns:
Returns the inputLayer.

setInputLayer

public void setInputLayer(InputLayer inputLayer)
Setter of the property inputLayer

Parameters:
inputLayer - The inputLayer to set.

getLayers

public java.util.ArrayList<InnerLayer> getLayers()
Getter of the property layers

Returns:
Returns the layers.

getLayers

public InnerLayer getLayers(int i)
Returns the layer at the specified position in this list.

Parameters:
index - index of layeer to return.
Returns:
the layer at the specified position in this list.
See Also:
List.get(int)

layersIterator

public java.util.Iterator<InnerLayer> layersIterator()
Returns an iterator over the layers in this list in proper sequence.

Returns:
an iterator over the layers in this list in proper sequence.
See Also:
List.iterator()

isLayersEmpty

public boolean isLayersEmpty()
Returns true if this list contains no layers.

Returns:
true if this list contains no layers.
See Also:
List.isEmpty()

containsLayers

public boolean containsLayers(InnerLayer innerLayer)
Returns true if this list contains the specified layer.

Parameters:
innerLayer - layer whose presence in this list is to be tested.
Returns:
true if this list contains the specified layer.
See Also:
List.contains(Object)

containsAllLayers

public boolean containsAllLayers(java.util.Collection<InnerLayer> layers)
Returns true if this list contains all of the layers of the specified collection.

Parameters:
layers - collection to be checked for containment in this list.
Returns:
true if this list contains all of the layers of the specified collection.
See Also:
List.containsAll(Collection)

layersSize

public int layersSize()
Returns the number of layers in this list.

Returns:
the number of layers in this list.
See Also:
List.size()

layersToArray

public InnerLayer[] layersToArray()
Returns an array containing all of the layers in this list in proper sequence.

Returns:
an array containing all of the layers in this list in proper sequence.
See Also:
List.toArray()

layersToArray

public InnerLayer[] layersToArray(InnerLayer[] layers)
Returns an array containing all of the layers in this list in proper sequence; the runtime type of the returned array is that of the specified array.

Parameters:
layers - the array into which the layers of this list are to be stored.
Returns:
an array containing all of the layers in this list in proper sequence.
See Also:
List.toArray(Object[])

addLayers

public void addLayers(int index,
                      InnerLayer innerLayer)
Inserts the specified layer at the specified position in this list (optional operation)

Parameters:
index - index at which the specified layer is to be inserted.
innerLayer - layer to be inserted.
See Also:
List.add(int,Object)

addLayers

public boolean addLayers(InnerLayer innerLayer)
Appends the specified layer to the end of this list (optional operation).

Parameters:
innerLayer - layer to be appended to this list.
Returns:
true (as per the general contract of the Collection.add method).
See Also:
List.add(Object)

removeLayers

public java.lang.Object removeLayers(int index)
Removes the layer at the specified position in this list (optional operation).

Parameters:
index - the index of the layer to removed.
Returns:
the layer previously at the specified position.
See Also:
List.remove(int)

removeLayers

public boolean removeLayers(InnerLayer innerLayer)
Removes the first occurrence in this list of the specified layer (optional operation).

Parameters:
innerLayer - layer to be removed from this list, if present.
Returns:
true if this list contained the specified layer.
See Also:
List.remove(Object)

clearLayers

public void clearLayers()
Removes all of the layers from this list (optional operation).

See Also:
List.clear()

setLayers

public void setLayers(java.util.ArrayList<InnerLayer> layers)
Setter of the property layers

Parameters:
layers - the layers to set.