org.encog.neural.flat
Class FlatNetwork
- java.lang.Object
-
- org.encog.neural.flat.FlatNetwork
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
- Direct Known Subclasses:
- FlatNetworkRBF
public class FlatNetwork extends java.lang.Object implements java.io.Serializable, java.lang.CloneableImplements 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
Fields Modifier and Type Field and Description static doubleDEFAULT_BIAS_ACTIVATIONThe default bias activation.static doubleNO_BIAS_ACTIVATIONThe value that indicates that there is no bias activation.
-
Constructor Summary
Constructors Constructor and Description FlatNetwork()Default constructor.FlatNetwork(FlatLayer[] layers)Create a flat network from an array of layers.FlatNetwork(FlatLayer[] layers, boolean dropout)FlatNetwork(int input, int hidden1, int hidden2, int output, boolean tanh)Construct a flat neural network.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublecalculateError(MLDataSet data)Calculate the error for this neural network.voidclearConnectionLimit()Clear any connection limits.voidclearContext()Clear any context neurons.FlatNetworkclone()Clone the network.voidcloneFlatNetwork(FlatNetwork result)Clone into the flat network passed in.voidcompute(double[] input, double[] output)Calculate the output for the given input.voiddecodeNetwork(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()intgetBeginTraining()double[]getBiasActivation()doublegetConnectionLimit()int[]getContextTargetOffset()int[]getContextTargetSize()intgetEncodeLength()intgetEndTraining()booleangetHasContext()intgetInputCount()int[]getLayerContextCount()int[]getLayerCounts()double[]getLayerDropoutRates()int[]getLayerFeedCounts()int[]getLayerIndex()intgetLayerNeuronCount(int l)Get the neuron count.double[]getLayerOutput()double[]getLayerSums()intgetLayerTotalNeuronCount(int l)Get the total (including bias and context) neuron cont for a layer.intgetNeuronCount()intgetOutputCount()doublegetWeight(int fromLayer, int fromNeuron, int toNeuron)Get the weight between the two layers.int[]getWeightIndex()double[]getWeights()java.lang.Class<?>hasSameActivationFunction()Neural networks with only one type of activation function offer certain optimization options.voidinit(FlatLayer[] layers, boolean dropout)Construct a flat network.booleanisLimited()voidrandomize()Perform a simple randomization of the weights of the neural network between -1 and 1.voidrandomize(double hi, double lo)Perform a simple randomization of the weights of the neural network between the specified hi and lo.voidsetActivationFunctions(ActivationFunction[] af)Set the activation functions.voidsetBeginTraining(int beginTraining)voidsetBiasActivation(double[] biasActivation)Set the bias activation.voidsetConnectionLimit(double connectionLimit)voidsetContextTargetOffset(int[] contextTargetOffset)Set the context target offset.voidsetContextTargetSize(int[] contextTargetSize)Set the context target size.voidsetEndTraining(int endTraining)voidsetHasContext(boolean hasContext)Set the hasContext property.voidsetInputCount(int inputCount)Set the input count.voidsetLayerContextCount(int[] layerContextCount)Set the layer context count.voidsetLayerCounts(int[] layerCounts)Set the layer counts.voidsetLayerDropoutRates(double[] layerDropoutRates)voidsetLayerFeedCounts(int[] layerFeedCounts)voidsetLayerIndex(int[] i)Set the layer index.voidsetLayerOutput(double[] layerOutput)Set the layer output.voidsetLayerSums(double[] d)Set the layer sums.voidsetOutputCount(int outputCount)Set the output count.voidsetWeightIndex(int[] weightIndex)Set the weight index.voidsetWeights(double[] weights)Set the weights.voidvalidateNeuron(int targetLayer, int neuron)Validate the the specified targetLayer and neuron are valid.
-
-
-
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(FlatLayer[] layers, boolean dropout)
-
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 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 void clearConnectionLimit()
Clear any connection limits.
-
clearContext
public void clearContext()
Clear any context neurons.
-
clone
public FlatNetwork clone()
Clone the network.- Overrides:
clonein classjava.lang.Object- Returns:
- A clone of the network.
-
cloneFlatNetwork
public 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.
-
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 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 ActivationFunction[] getActivationFunctions()
- Returns:
- The activation functions.
-
getBeginTraining
public int getBeginTraining()
- Returns:
- the beginTraining
-
getBiasActivation
public double[] getBiasActivation()
- Returns:
- The bias activation.
-
getConnectionLimit
public double getConnectionLimit()
- Returns:
- the connectionLimit
-
getContextTargetOffset
public int[] getContextTargetOffset()
- Returns:
- The offset of the context target for each layer.
-
getContextTargetSize
public int[] getContextTargetSize()
- Returns:
- The context target size for each layer. Zero if the layer does not feed a context layer.
-
getEncodeLength
public int getEncodeLength()
- Returns:
- The length of the array the network would encode to.
-
getEndTraining
public int getEndTraining()
- Returns:
- the endTraining
-
getHasContext
public boolean getHasContext()
- Returns:
- True if this network has context.
-
getInputCount
public int getInputCount()
- Returns:
- The number of input neurons.
-
getLayerContextCount
public int[] getLayerContextCount()
- Returns:
- The layer context count.
-
getLayerCounts
public int[] getLayerCounts()
- Returns:
- The number of neurons in each layer.
-
getLayerFeedCounts
public int[] getLayerFeedCounts()
- Returns:
- The number of neurons in each layer that are fed by the previous layer.
-
getLayerIndex
public int[] getLayerIndex()
- Returns:
- Indexes into the weights for the start of each layer.
-
getLayerOutput
public double[] getLayerOutput()
- Returns:
- The output for each layer.
-
getNeuronCount
public int getNeuronCount()
- Returns:
- The neuron count.
-
getOutputCount
public int getOutputCount()
- Returns:
- The number of output neurons.
-
getWeightIndex
public int[] getWeightIndex()
- Returns:
- The index of each layer in the weight and threshold array.
-
getWeights
public double[] getWeights()
- Returns:
- The index of each layer in the weight and threshold array.
-
hasSameActivationFunction
public java.lang.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 void init(FlatLayer[] layers, boolean dropout)
Construct a flat network.- Parameters:
layers- The layers of the network to create.dropout- Flag to enable dropout rate for each layer.
-
isLimited
public boolean isLimited()
- Returns:
- the isLimited
-
randomize
public void randomize()
Perform a simple randomization of the weights of the neural network between -1 and 1.
-
randomize
public 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 void setActivationFunctions(ActivationFunction[] af)
Set the activation functions.- Parameters:
af- The activation functions.
-
setBeginTraining
public void setBeginTraining(int beginTraining)
- Parameters:
beginTraining- the beginTraining to set
-
setBiasActivation
public void setBiasActivation(double[] biasActivation)
Set the bias activation.- Parameters:
biasActivation- The bias activation.
-
setConnectionLimit
public void setConnectionLimit(double connectionLimit)
- Parameters:
connectionLimit- the connectionLimit to set
-
setContextTargetOffset
public void setContextTargetOffset(int[] contextTargetOffset)
Set the context target offset.- Parameters:
contextTargetOffset- The context target offset.
-
setContextTargetSize
public 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 void setHasContext(boolean hasContext)
Set the hasContext property.- Parameters:
hasContext- True if the network has context.
-
setInputCount
public void setInputCount(int inputCount)
Set the input count.- Parameters:
inputCount- The input count.
-
setLayerContextCount
public void setLayerContextCount(int[] layerContextCount)
Set the layer context count.- Parameters:
layerContextCount- The layer context count.
-
setLayerCounts
public void setLayerCounts(int[] layerCounts)
Set the layer counts.- Parameters:
layerCounts- The layer counts.
-
setLayerFeedCounts
public void setLayerFeedCounts(int[] layerFeedCounts)
-
setLayerIndex
public void setLayerIndex(int[] i)
Set the layer index.- Parameters:
i- The layer index.
-
setLayerOutput
public void setLayerOutput(double[] layerOutput)
Set the layer output.- Parameters:
layerOutput- The layer output.
-
setOutputCount
public void setOutputCount(int outputCount)
Set the output count.- Parameters:
outputCount- The output count.
-
setWeightIndex
public void setWeightIndex(int[] weightIndex)
Set the weight index.- Parameters:
weightIndex- The weight index.
-
setWeights
public 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.
-
getLayerDropoutRates
public double[] getLayerDropoutRates()
-
setLayerDropoutRates
public void setLayerDropoutRates(double[] layerDropoutRates)
-
getWeight
public double getWeight(int fromLayer, int fromNeuron, int toNeuron)Get the weight between the two layers.- Parameters:
fromLayer- The from layer.fromNeuron- The from neuron.toNeuron- The to neuron.- Returns:
- The weight value.
-
validateNeuron
public void validateNeuron(int targetLayer, int neuron)Validate the the specified targetLayer and neuron are valid.- Parameters:
targetLayer- The target layer.neuron- The target neuron.
-
getLayerTotalNeuronCount
public int getLayerTotalNeuronCount(int l)
Get the total (including bias and context) neuron cont for a layer.- Parameters:
l- The layer.- Returns:
- The count.
-
getLayerNeuronCount
public int getLayerNeuronCount(int l)
Get the neuron count.- Parameters:
l- The layer.- Returns:
- The neuron count.
-
-
DMelt 3.0 © DataMelt by jWork.ORG