org.encog.neural.flat
Class FlatNetwork

java.lang.Object
  extended by org.encog.neural.flat.FlatNetwork
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FlatNetworkRBF

public class FlatNetwork
extends Object
implements Serializable

Implements a flat (vector based) neural network in the Encog Engine. This is meant to be a very highly efficient feedforward, or simple recurrent, neural network. It uses a minimum of objects and is designed with one principal in mind-- SPEED. Readability, code reuse, object oriented programming are all secondary in consideration. Vector based neural networks are also very good for GPU processing. The flat network classes will make use of the GPU if you have enabled GPU processing. See the Encog class for more info.

See Also:
Serialized Form

Field Summary
static double DEFAULT_BIAS_ACTIVATION
          The default bias activation.
static double NO_BIAS_ACTIVATION
          The value that indicates that there is no bias activation.
 
Constructor Summary
FlatNetwork()
          Default constructor.
FlatNetwork(FlatLayer[] layers)
          Create a flat network from an array of layers.
FlatNetwork(int input, int hidden1, int hidden2, int output, boolean tanh)
          Construct a flat neural network.
 
Method Summary
 double calculateError(MLDataSet data)
          Calculate the error for this neural network.
 void clearConnectionLimit()
          Clear any connection limits.
 void clearContext()
          Clear any context neurons.
 FlatNetwork clone()
          Clone the network.
 void cloneFlatNetwork(FlatNetwork result)
          Clone into the flat network passed in.
 void compute(double[] input, double[] output)
          Calculate the output for the given input.
protected  void computeLayer(int currentLayer)
          Calculate a layer.
 void decodeNetwork(double[] data)
          Decode the specified data into the weights of the neural network.
 double[] encodeNetwork()
          Encode the neural network to an array of doubles.
 ActivationFunction[] getActivationFunctions()
           
 int getBeginTraining()
           
 double[] getBiasActivation()
           
 double getConnectionLimit()
           
 int[] getContextTargetOffset()
           
 int[] getContextTargetSize()
           
 int getEncodeLength()
           
 int getEndTraining()
           
 boolean getHasContext()
           
 int getInputCount()
           
 int[] getLayerContextCount()
           
 int[] getLayerCounts()
           
 int[] getLayerFeedCounts()
           
 int[] getLayerIndex()
           
 double[] getLayerOutput()
           
 double[] getLayerSums()
           
 int getNeuronCount()
           
 int getOutputCount()
           
 int[] getWeightIndex()
           
 double[] getWeights()
           
 Class<?> hasSameActivationFunction()
          Neural networks with only one type of activation function offer certain optimization options.
 void init(FlatLayer[] layers)
          Construct a flat network.
 boolean isLimited()
           
 void randomize()
          Perform a simple randomization of the weights of the neural network between -1 and 1.
 void randomize(double hi, double lo)
          Perform a simple randomization of the weights of the neural network between the specified hi and lo.
 void setActivationFunctions(ActivationFunction[] af)
          Set the activation functions.
 void setBeginTraining(int beginTraining)
           
 void setBiasActivation(double[] biasActivation)
          Set the bias activation.
 void setConnectionLimit(double connectionLimit)
           
 void setContextTargetOffset(int[] contextTargetOffset)
          Set the context target offset.
 void setContextTargetSize(int[] contextTargetSize)
          Set the context target size.
 void setEndTraining(int endTraining)
           
 void setHasContext(boolean hasContext)
          Set the hasContext property.
 void setInputCount(int inputCount)
          Set the input count.
 void setLayerContextCount(int[] layerContextCount)
          Set the layer context count.
 void setLayerCounts(int[] layerCounts)
          Set the layer counts.
 void setLayerFeedCounts(int[] layerFeedCounts)
           
 void setLayerIndex(int[] i)
          Set the layer index.
 void setLayerOutput(double[] layerOutput)
          Set the layer output.
 void setLayerSums(double[] d)
          Set the layer sums.
 void setOutputCount(int outputCount)
          Set the output count.
 void setWeightIndex(int[] weightIndex)
          Set the weight index.
 void setWeights(double[] weights)
          Set the weights.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BIAS_ACTIVATION

public static final double DEFAULT_BIAS_ACTIVATION
The default bias activation.

See Also:
Constant Field Values

NO_BIAS_ACTIVATION

public static final double NO_BIAS_ACTIVATION
The value that indicates that there is no bias activation.

See Also:
Constant Field Values
Constructor Detail

FlatNetwork

public FlatNetwork()
Default constructor.


FlatNetwork

public FlatNetwork(FlatLayer[] layers)
Create a flat network from an array of layers.

Parameters:
layers - The layers.

FlatNetwork

public FlatNetwork(int input,
                   int hidden1,
                   int hidden2,
                   int output,
                   boolean tanh)
Construct a flat neural network.

Parameters:
input - Neurons in the input layer.
hidden1 - Neurons in the first hidden layer. Zero for no first hidden layer.
hidden2 - Neurons in the second hidden layer. Zero for no second hidden layer.
output - Neurons in the output layer.
tanh - True if this is a tanh activation, false for sigmoid.
Method Detail

calculateError

public final double calculateError(MLDataSet 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.

clearConnectionLimit

public final void clearConnectionLimit()
Clear any connection limits.


clearContext

public final void clearContext()
Clear any context neurons.


clone

public FlatNetwork clone()
Clone the network.

Overrides:
clone in class Object
Returns:
A clone of the network.

cloneFlatNetwork

public final void cloneFlatNetwork(FlatNetwork result)
Clone into the flat network passed in.

Parameters:
result - The network to copy into.

compute

public void compute(double[] input,
                    double[] output)
Calculate the output for the given input.

Parameters:
input - The input.
output - Output will be placed here.

computeLayer

protected void computeLayer(int currentLayer)
Calculate a layer.

Parameters:
currentLayer - The layer to calculate.

decodeNetwork

public void decodeNetwork(double[] data)
Decode the specified data into the weights of the neural network. This method performs the opposite of encodeNetwork.

Parameters:
data - The data to be decoded.

encodeNetwork

public final double[] encodeNetwork()
Encode the neural network to an array of doubles. This includes the network weights. To read this into a neural network, use the decodeNetwork method.

Returns:
The encoded network.

getActivationFunctions

public final ActivationFunction[] getActivationFunctions()
Returns:
The activation functions.

getBeginTraining

public final int getBeginTraining()
Returns:
the beginTraining

getBiasActivation

public final double[] getBiasActivation()
Returns:
The bias activation.

getConnectionLimit

public final double getConnectionLimit()
Returns:
the connectionLimit

getContextTargetOffset

public final int[] getContextTargetOffset()
Returns:
The offset of the context target for each layer.

getContextTargetSize

public final int[] getContextTargetSize()
Returns:
The context target size for each layer. Zero if the layer does not feed a context layer.

getEncodeLength

public final int getEncodeLength()
Returns:
The length of the array the network would encode to.

getEndTraining

public final int getEndTraining()
Returns:
the endTraining

getHasContext

public final boolean getHasContext()
Returns:
True if this network has context.

getInputCount

public final int getInputCount()
Returns:
The number of input neurons.

getLayerContextCount

public final int[] getLayerContextCount()
Returns:
The layer context count.

getLayerCounts

public final int[] getLayerCounts()
Returns:
The number of neurons in each layer.

getLayerFeedCounts

public final int[] getLayerFeedCounts()
Returns:
The number of neurons in each layer that are fed by the previous layer.

getLayerIndex

public final int[] getLayerIndex()
Returns:
Indexes into the weights for the start of each layer.

getLayerOutput

public final double[] getLayerOutput()
Returns:
The output for each layer.

getNeuronCount

public final int getNeuronCount()
Returns:
The neuron count.

getOutputCount

public final int getOutputCount()
Returns:
The number of output neurons.

getWeightIndex

public final int[] getWeightIndex()
Returns:
The index of each layer in the weight and threshold array.

getWeights

public final double[] getWeights()
Returns:
The index of each layer in the weight and threshold array.

hasSameActivationFunction

public final Class<?> hasSameActivationFunction()
Neural networks with only one type of activation function offer certain optimization options. This method determines if only a single activation function is used.

Returns:
The number of the single activation function, or -1 if there are no activation functions or more than one type of activation function.

init

public final void init(FlatLayer[] layers)
Construct a flat network.

Parameters:
layers - The layers of the network to create.

isLimited

public final boolean isLimited()
Returns:
the isLimited

randomize

public final void randomize()
Perform a simple randomization of the weights of the neural network between -1 and 1.


randomize

public final void randomize(double hi,
                            double lo)
Perform a simple randomization of the weights of the neural network between the specified hi and lo.

Parameters:
hi - The network high.
lo - The network low.

setActivationFunctions

public final void setActivationFunctions(ActivationFunction[] af)
Set the activation functions.

Parameters:
af - The activation functions.

setBeginTraining

public final void setBeginTraining(int beginTraining)
Parameters:
beginTraining - the beginTraining to set

setBiasActivation

public final void setBiasActivation(double[] biasActivation)
Set the bias activation.

Parameters:
biasActivation - The bias activation.

setConnectionLimit

public final void setConnectionLimit(double connectionLimit)
Parameters:
connectionLimit - the connectionLimit to set

setContextTargetOffset

public final void setContextTargetOffset(int[] contextTargetOffset)
Set the context target offset.

Parameters:
contextTargetOffset - The context target offset.

setContextTargetSize

public final void setContextTargetSize(int[] contextTargetSize)
Set the context target size.

Parameters:
contextTargetSize - The context target size.

setEndTraining

public void setEndTraining(int endTraining)
Parameters:
endTraining - the endTraining to set

setHasContext

public final void setHasContext(boolean hasContext)
Set the hasContext property.

Parameters:
hasContext - True if the network has context.

setInputCount

public final void setInputCount(int inputCount)
Set the input count.

Parameters:
inputCount - The input count.

setLayerContextCount

public final void setLayerContextCount(int[] layerContextCount)
Set the layer context count.

Parameters:
layerContextCount - The layer context count.

setLayerCounts

public final void setLayerCounts(int[] layerCounts)
Set the layer counts.

Parameters:
layerCounts - The layer counts.

setLayerFeedCounts

public final void setLayerFeedCounts(int[] layerFeedCounts)

setLayerIndex

public final void setLayerIndex(int[] i)
Set the layer index.

Parameters:
i - The layer index.

setLayerOutput

public final void setLayerOutput(double[] layerOutput)
Set the layer output.

Parameters:
layerOutput - The layer output.

setOutputCount

public final void setOutputCount(int outputCount)
Set the output count.

Parameters:
outputCount - The output count.

setWeightIndex

public final void setWeightIndex(int[] weightIndex)
Set the weight index.

Parameters:
weightIndex - The weight index.

setWeights

public final void setWeights(double[] weights)
Set the weights.

Parameters:
weights - The weights.

getLayerSums

public double[] getLayerSums()
Returns:
the layerSums

setLayerSums

public void setLayerSums(double[] d)
Set the layer sums.

Parameters:
d - The layer sums.


Copyright © 2012. All Rights Reserved.