org.encog.neural.freeform
Class FreeformNetwork
- java.lang.Object
-
- org.encog.ml.BasicML
-
- org.encog.neural.freeform.FreeformNetwork
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, MLClassification, MLContext, MLEncodable, MLError, MLInput, MLInputOutput, MLMethod, MLOutput, MLProperties, MLRegression, MLResettable
public class FreeformNetwork extends BasicML implements MLContext, java.lang.Cloneable, MLRegression, MLEncodable, MLResettable, MLClassification, MLError
Implements a freefrom neural network. A freeform neural network can represent much more advanced structures than the flat networks that the Encog BasicNetwork implements. However, while freeform networks are more advanced than the BasicNetwork, they are also much slower. Freeform networks allow just about any neuron to be connected to another neuron. You can have neuron layers if you want, but they are not required.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description FreeformNetwork()Default constructor.FreeformNetwork(BasicNetwork network)Craete a freeform network from a basic network.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublecalculateError(MLDataSet data)Calculate the error of the ML method, given a dataset.intclassify(MLData input)Classify the input into a group.voidclearContext()Clear the context.java.lang.Objectclone()Return a clone of this neural network.MLDatacompute(MLData input)Compute regression.voidconnectLayers(FreeformLayer source, FreeformLayer target)Connect two layers.voidConnectLayers(FreeformLayer source, FreeformLayer target, ActivationFunction theActivationFunction)Connect two layers, assume bias activation of 1.0 and non-recurrent connection.voidconnectLayers(FreeformLayer source, FreeformLayer target, ActivationFunction theActivationFunction, double biasActivation, boolean isRecurrent)Connect two layers.FreeformLayercreateContext(FreeformLayer source, FreeformLayer target)Create a context connection, such as those used by Jordan/Elmann.static FreeformNetworkcreateElman(int input, int hidden1, int output, ActivationFunction af)Construct an Elmann recurrent neural network.static FreeformNetworkcreateFeedforward(int input, int hidden1, int hidden2, int output, ActivationFunction af)Create a feedforward freeform neural network.FreeformLayercreateInputLayer(int neuronCount)Create the input layer.FreeformLayercreateLayer(int neuronCount)Create a hidden layer.FreeformLayercreateOutputLayer(int neuronCount)Create the output layer.voiddecodeFromArray(double[] encoded)Decode an array to this object.intencodedArrayLength()voidencodeToArray(double[] encoded)Encode the object to the specified array.intgetInputCount()intgetOutputCount()FreeformLayergetOutputLayer()voidperformConnectionTask(ConnectionTask task)Perform the specified connection task.voidperformNeuronTask(NeuronTask task)Perform the specified neuron task.voidreset()Reset the weights.voidreset(int seed)Reset the weights with a seed.voidtempTrainingAllocate(int neuronSize, int connectionSize)Allocate temp training space.voidtempTrainingClear()Clear the temp training data.voidupdateContext()Update context.voidupdateProperties()Update any objeccts when a property changes.-
Methods inherited from class org.encog.ml.BasicML
getProperties, getPropertyDouble, getPropertyLong, getPropertyString, setProperty, setProperty, setProperty
-
-
-
-
Constructor Detail
-
FreeformNetwork
public FreeformNetwork()
Default constructor. Typically should not be directly used.
-
FreeformNetwork
public FreeformNetwork(BasicNetwork network)
Craete a freeform network from a basic network.- Parameters:
network- The basic network to use.
-
-
Method Detail
-
createElman
public static FreeformNetwork createElman(int input, int hidden1, int output, ActivationFunction af)
Construct an Elmann recurrent neural network.- Parameters:
input- The input count.hidden1- The hidden count.output- The output count.af- The activation function.- Returns:
- The newly created network.
-
createFeedforward
public static FreeformNetwork createFeedforward(int input, int hidden1, int hidden2, int output, ActivationFunction af)
Create a feedforward freeform neural network.- Parameters:
input- The input count.hidden1- The first hidden layer count, zero if none.hidden2- The second hidden layer count, zero if none.output- The output count.af- The activation function.- Returns:
- The newly crated network.
-
calculateError
public double calculateError(MLDataSet data)
Calculate the error of the ML method, given a dataset.- Specified by:
calculateErrorin interfaceMLError- Parameters:
data- The dataset.- Returns:
- The error.
-
classify
public int classify(MLData input)
Classify the input into a group.- Specified by:
classifyin interfaceMLClassification- Parameters:
input- The input data to classify.- Returns:
- The group that the data was classified into.
-
clearContext
public void clearContext()
Clear the context.- Specified by:
clearContextin interfaceMLContext
-
clone
public java.lang.Object clone()
Return a clone of this neural network. Including structure, weights and bias values. This is a deep copy.- Overrides:
clonein classjava.lang.Object- Returns:
- A cloned copy of the neural network.
-
compute
public MLData compute(MLData input)
Compute regression.- Specified by:
computein interfaceMLRegression- Parameters:
input- The input data.- Returns:
- The output data.
-
connectLayers
public void connectLayers(FreeformLayer source, FreeformLayer target)
Connect two layers. These layers will be connected with a TANH activation function in a non-recurrent way. A bias activation of 1.0 will be used, if needed.- Parameters:
source- The source layer.target- The target layer.
-
connectLayers
public void connectLayers(FreeformLayer source, FreeformLayer target, ActivationFunction theActivationFunction, double biasActivation, boolean isRecurrent)
Connect two layers.- Parameters:
source- The source layer.target- The target layer.theActivationFunction- The activation function to use.biasActivation- The bias activation to use.isRecurrent- True, if this is a recurrent connection.
-
ConnectLayers
public void ConnectLayers(FreeformLayer source, FreeformLayer target, ActivationFunction theActivationFunction)
Connect two layers, assume bias activation of 1.0 and non-recurrent connection.- Parameters:
source- The source layer.target- The target layer.theActivationFunction- The activation function.
-
createContext
public FreeformLayer createContext(FreeformLayer source, FreeformLayer target)
Create a context connection, such as those used by Jordan/Elmann.- Parameters:
source- The source layer.target- The target layer.- Returns:
- The newly created context layer.
-
createInputLayer
public FreeformLayer createInputLayer(int neuronCount)
Create the input layer.- Parameters:
neuronCount- The input neuron count.- Returns:
- The newly created layer.
-
createLayer
public FreeformLayer createLayer(int neuronCount)
Create a hidden layer.- Parameters:
neuronCount- The neuron count.- Returns:
- The newly created layer.
-
createOutputLayer
public FreeformLayer createOutputLayer(int neuronCount)
Create the output layer.- Parameters:
neuronCount- The neuron count.- Returns:
- The newly created output layer.
-
decodeFromArray
public void decodeFromArray(double[] encoded)
Decode an array to this object.- Specified by:
decodeFromArrayin interfaceMLEncodable- Parameters:
encoded- The encoded array.
-
encodedArrayLength
public int encodedArrayLength()
- Specified by:
encodedArrayLengthin interfaceMLEncodable- Returns:
- The length of an encoded array.
-
encodeToArray
public void encodeToArray(double[] encoded)
Encode the object to the specified array.- Specified by:
encodeToArrayin interfaceMLEncodable- Parameters:
encoded- The array.
-
getInputCount
public int getInputCount()
- Specified by:
getInputCountin interfaceMLInput- Returns:
- The input.
-
getOutputCount
public int getOutputCount()
- Specified by:
getOutputCountin interfaceMLOutput- Returns:
- The output count.
-
getOutputLayer
public FreeformLayer getOutputLayer()
- Returns:
- The output layer.
-
performConnectionTask
public void performConnectionTask(ConnectionTask task)
Perform the specified connection task. This task will be performed over all connections.- Parameters:
task- The connection task.
-
performNeuronTask
public void performNeuronTask(NeuronTask task)
Perform the specified neuron task. This task will be executed over all neurons.- Parameters:
task- The neuron task to perform.
-
reset
public void reset()
Reset the weights.- Specified by:
resetin interfaceMLResettable
-
reset
public void reset(int seed)
Reset the weights with a seed.- Specified by:
resetin interfaceMLResettable- Parameters:
seed- The seed value.
-
tempTrainingAllocate
public void tempTrainingAllocate(int neuronSize, int connectionSize)Allocate temp training space.- Parameters:
neuronSize- The number of elements to allocate on each neuron.connectionSize- The number of elements to allocate on each connection.
-
tempTrainingClear
public void tempTrainingClear()
Clear the temp training data.
-
updateContext
public void updateContext()
Update context.
-
updateProperties
public void updateProperties()
Update any objeccts when a property changes.- Specified by:
updatePropertiesin interfaceMLProperties- Specified by:
updatePropertiesin classBasicML
-
-
DMelt 3.0 © DataMelt by jWork.ORG