org.encog.neural.networks.structure
Class NeuralStructure

java.lang.Object
  extended by org.encog.neural.networks.structure.NeuralStructure
All Implemented Interfaces:
Serializable

public class NeuralStructure
extends Object
implements Serializable

Holds "cached" information about the structure of the neural network. This is a very good performance boost since the neural network does not need to traverse itself each time a complete collection of layers or synapses is needed.

Author:
jheaton
See Also:
Serialized Form

Constructor Summary
NeuralStructure(BasicNetwork network)
          Construct a structure object for the specified network.
 
Method Summary
 void assignID()
          Assign an ID to every layer that does not already have one.
 void assignID(Layer layer)
          Assign an ID to the specified layer.
 int calculateSize()
          Calculate the size that an array should be to hold all of the weights and bias values.
 boolean containsLayerType(Class<?> type)
          Determine if the network contains a layer of the specified type.
 void enforceLimit()
          Enforce that all connections are above the connection limit.
 void finalizeStructure()
          Build the synapse and layer structure.
 Synapse findNextSynapseByLayerType(Layer layer, Class<? extends Layer> type)
          Find the next synapse by layer type.
 Synapse findPreviousSynapseByLayerType(Layer layer, Class<? extends Layer> type)
          Find previous synapse by layer type.
 Synapse findSynapse(Layer fromLayer, Layer toLayer, boolean required)
          Find the specified synapse, throw an error if it is required.
 void flatten()
          Flatten the network.
 void flattenWeights()
          Flatten the weights, do not restructure.
 double getConnectionLimit()
           
 FlatNetwork getFlat()
           
 FlatUpdateNeeded getFlatUpdate()
           
 List<Layer> getLayers()
           
 BasicNetwork getNetwork()
           
 int getNextID()
          Get the next layer id.
 Collection<Layer> getPreviousLayers(Layer targetLayer)
          Get the previous layers from the specified layer.
 List<Synapse> getPreviousSynapses(Layer targetLayer)
          Get the previous synapses.
 List<Synapse> getSynapses()
           
 boolean isConnectionLimited()
           
 boolean isRecurrent()
           
 List<String> nameLayer(Layer layer)
          Obtain a name for the specified layer.
 void setFlatUpdate(FlatUpdateNeeded flatUpdate)
          Set the type of flat update needed.
 void sort()
          Sort the layers and synapses.
 void unflattenWeights()
          Unflatten the weights.
 void updateFlatNetwork()
          Update the flat network.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NeuralStructure

public NeuralStructure(BasicNetwork network)
Construct a structure object for the specified network.

Parameters:
network - The network to construct a structure for.
Method Detail

assignID

public void assignID()
Assign an ID to every layer that does not already have one.


assignID

public void assignID(Layer layer)
Assign an ID to the specified layer.

Parameters:
layer - The layer to get an ID assigned.

calculateSize

public int calculateSize()
Calculate the size that an array should be to hold all of the weights and bias values.

Returns:
The size of the calculated array.

containsLayerType

public boolean containsLayerType(Class<?> type)
Determine if the network contains a layer of the specified type.

Parameters:
type - The layer type we are looking for.
Returns:
True if this layer type is present.

enforceLimit

public void enforceLimit()
Enforce that all connections are above the connection limit. Any connections below this limit will be severed.


finalizeStructure

public void finalizeStructure()
Build the synapse and layer structure. This method should be called after you are done adding layers to a network, or change the network's logic property.


findNextSynapseByLayerType

public Synapse findNextSynapseByLayerType(Layer layer,
                                          Class<? extends Layer> type)
Find the next synapse by layer type.

Parameters:
layer - The layer to search from.
type - The synapse type to look for.
Returns:
The synapse found, or null.

findPreviousSynapseByLayerType

public Synapse findPreviousSynapseByLayerType(Layer layer,
                                              Class<? extends Layer> type)
Find previous synapse by layer type.

Parameters:
layer - The layer to start from.
type - The type of layer.
Returns:
The synapse found.

findSynapse

public Synapse findSynapse(Layer fromLayer,
                           Layer toLayer,
                           boolean required)
Find the specified synapse, throw an error if it is required.

Parameters:
fromLayer - The from layer.
toLayer - The to layer.
required - Is this required?
Returns:
The synapse, if it exists, otherwise null.

flatten

public void flatten()
Flatten the network. Generate the flat network.


flattenWeights

public void flattenWeights()
Flatten the weights, do not restructure.


getConnectionLimit

public double getConnectionLimit()
Returns:
The connection limit.

getFlat

public FlatNetwork getFlat()
Returns:
The flat network.

getFlatUpdate

public FlatUpdateNeeded getFlatUpdate()
Returns:
The type of update currently needed.

getLayers

public List<Layer> getLayers()
Returns:
The layers in this neural network.

getNetwork

public BasicNetwork getNetwork()
Returns:
The network this structure belongs to.

getNextID

public int getNextID()
Get the next layer id.

Returns:
The next layer id.

getPreviousLayers

public Collection<Layer> getPreviousLayers(Layer targetLayer)
Get the previous layers from the specified layer.

Parameters:
targetLayer - The target layer.
Returns:
The previous layers.

getPreviousSynapses

public List<Synapse> getPreviousSynapses(Layer targetLayer)
Get the previous synapses.

Parameters:
targetLayer - The layer to get the previous layers from.
Returns:
A collection of synapses.

getSynapses

public List<Synapse> getSynapses()
Returns:
All synapses in the neural network.

isConnectionLimited

public boolean isConnectionLimited()
Returns:
True if this is not a fully connected feedforward network.

isRecurrent

public boolean isRecurrent()
Returns:
Are there any context layers.

nameLayer

public List<String> nameLayer(Layer layer)
Obtain a name for the specified layer.

Parameters:
layer - The layer to name.
Returns:
The name of this layer.

setFlatUpdate

public void setFlatUpdate(FlatUpdateNeeded flatUpdate)
Set the type of flat update needed.

Parameters:
flatUpdate - The type of flat update needed.

sort

public void sort()
Sort the layers and synapses.


unflattenWeights

public void unflattenWeights()
Unflatten the weights.


updateFlatNetwork

public void updateFlatNetwork()
Update the flat network.



Copyright © 2011. All Rights Reserved.