org.neuroph.core
Class NeuralNetwork<L extends LearningRule>
- java.lang.Object
-
- org.neuroph.core.NeuralNetwork<L>
-
- All Implemented Interfaces:
- java.io.Serializable
- Direct Known Subclasses:
- Adaline, BAM, CompetitiveNetwork, ConvolutionalNetwork, ElmanNetwork, Hopfield, Instar, JordanNetwork, Kohonen, MatrixMultiLayerPerceptron, MaxNet, MultiLayerPerceptron, NeuroFuzzyPerceptron, Outstar, Perceptron, RBFNetwork, RecommenderNetwork, RectifierNeuralNetwork, SupervisedHebbianNetwork, UnsupervisedHebbianNetwork
public class NeuralNetwork<L extends LearningRule> extends java.lang.Object implements java.io.SerializableBase class for artificial neural networks. It provides generic structure and functionality for the neural networks. Neural network contains a collection of neuron layers and learning rule. Custom neural networks are created by deriving from this class, creating layers of interconnected network specific neurons, and setting network specific learning rule.
- See Also:
Layer,LearningRule, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description NeuralNetwork()Creates an instance of empty neural network.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidaddLayer(int index, Layer layer)Adds layer to specified index position in networkvoidaddLayer(Layer layer)Adds layer to neural networkvoidaddListener(NeuralNetworkEventListener listener)voidaddPlugin(PluginBase plugin)Adds plugin to neural networkvoidcalculate()Performs calculation on whole networkvoidcreateConnection(Neuron fromNeuron, Neuron toNeuron, double weightVal)Creates connection with specified weight value between specified neuronsstatic NeuralNetworkcreateFromFile(java.io.File file)Loads and return s neural network instance from specified filestatic NeuralNetworkcreateFromFile(java.lang.String filePath)voidfireNetworkEvent(NeuralNetworkEvent evt)java.util.List<Neuron>getInputNeurons()Returns input neuronsintgetInputsCount()Gets number of input neuronsjava.lang.StringgetLabel()Get network labelLayergetLayerAt(int index)Returns layer at specified indexjava.util.List<Layer>getLayers()Returns layers arrayintgetLayersCount()Returns number of layers in networkLgetLearningRule()Returns the learning algorithm of this networkNeuralNetworkTypegetNetworkType()Returns type of this networkdouble[]getOutput()Returns network output vector.java.util.List<Neuron>getOutputNeurons()Returns output neuronsintgetOutputsCount()<T extends PluginBase>
TgetPlugin(java.lang.Class<T> pluginClass)Returns the requested pluginjava.lang.Double[]getWeights()Returns all network weights as an double arrayintindexOf(Layer layer)Returns index position of the specified layerbooleanisEmpty()voidlearn(DataSet trainingSet)Learn the specified training setvoidlearn(DataSet trainingSet, L learningRule)Learn the specified training set, using specified learning rulestatic NeuralNetworkload(java.io.InputStream inputStream)Loads neural network from the specified InputStream.static NeuralNetworkload(java.lang.String filePath)Deprecated.Use createFromFile method insteadvoidpauseLearning()Pause the learning - puts learning thread in ca state.voidrandomizeWeights()Randomizes connection weights for the whole networkvoidrandomizeWeights(double minWeight, double maxWeight)Randomizes connection weights for the whole network within specified value rangevoidrandomizeWeights(java.util.Random random)Randomizes connection weights for the whole network using specified random generatorvoidrandomizeWeights(WeightsRandomizer randomizer)Randomizes connection weights for the whole network using specified randomizervoidremoveLayer(Layer layer)Removes specified layer from networkvoidremoveLayerAt(int index)Removes layer at specified index position from netvoidremoveListener(NeuralNetworkEventListener listener)voidremovePlugin(java.lang.Class pluginClass)Removes the plugin with specified namevoidreset()Resets the activation levels for whole networkvoidresumeLearning()Resumes paused learning - notifies the learning rule to continuevoidsave(java.lang.String filePath)Saves neural network into the specified file.voidsetInput(double... inputVector)Sets network input.voidsetInputNeurons(java.util.List<Neuron> inputNeurons)Sets input neuronsvoidsetLabel(java.lang.String label)Set network labelvoidsetLearningRule(L learningRule)Sets learning algorithm for this networkvoidsetNetworkType(NeuralNetworkType type)Sets type for this networkvoidsetOutputLabels(java.lang.String[] labels)Sets labels for output neuronsvoidsetOutputNeurons(java.util.List<Neuron> outputNeurons)Sets output neuronsvoidsetWeights(double[] weights)Sets network weights from the specified double arrayvoidstopLearning()Stops learningjava.lang.StringtoString()
-
-
-
Constructor Detail
-
NeuralNetwork
public NeuralNetwork()
Creates an instance of empty neural network.
-
-
Method Detail
-
addLayer
public void addLayer(Layer layer)
Adds layer to neural network- Parameters:
layer- layer to add
-
addLayer
public void addLayer(int index, Layer layer)Adds layer to specified index position in network- Parameters:
index- index position to add layerlayer- layer to add
-
removeLayer
public void removeLayer(Layer layer)
Removes specified layer from network- Parameters:
layer- layer to remove- Throws:
java.lang.Exception
-
removeLayerAt
public void removeLayerAt(int index)
Removes layer at specified index position from net- Parameters:
index- int value represents index postion of layer which should be removed
-
getLayers
public java.util.List<Layer> getLayers()
Returns layers array- Returns:
- array of layers
-
getLayerAt
public Layer getLayerAt(int index)
Returns layer at specified index- Parameters:
index- layer index position- Returns:
- layer at specified index position
-
indexOf
public int indexOf(Layer layer)
Returns index position of the specified layer- Parameters:
layer- requested Layer object- Returns:
- layer position index
-
getLayersCount
public int getLayersCount()
Returns number of layers in network- Returns:
- number of layes in net
-
setInput
public void setInput(double... inputVector) throws VectorSizeMismatchExceptionSets network input. Input is an array of double values.- Parameters:
inputVector- network input as double array- Throws:
VectorSizeMismatchException
-
getOutput
public double[] getOutput()
Returns network output vector. Output vector is an array collection of Double values.- Returns:
- network output vector
-
calculate
public void calculate()
Performs calculation on whole network
-
reset
public void reset()
Resets the activation levels for whole network
-
learn
public void learn(DataSet trainingSet)
Learn the specified training set- Parameters:
trainingSet- set of training elements to learn
-
learn
public void learn(DataSet trainingSet, L learningRule)
Learn the specified training set, using specified learning rule- Parameters:
trainingSet- set of training elements to learnlearningRule- instance of learning rule to use for learning
-
stopLearning
public void stopLearning()
Stops learning
-
pauseLearning
public void pauseLearning()
Pause the learning - puts learning thread in ca state. Makes sense only wen learning is done in new thread with learnInNewThread() method
-
resumeLearning
public void resumeLearning()
Resumes paused learning - notifies the learning rule to continue
-
randomizeWeights
public void randomizeWeights()
Randomizes connection weights for the whole network
-
randomizeWeights
public void randomizeWeights(double minWeight, double maxWeight)Randomizes connection weights for the whole network within specified value range
-
randomizeWeights
public void randomizeWeights(java.util.Random random)
Randomizes connection weights for the whole network using specified random generator
-
randomizeWeights
public void randomizeWeights(WeightsRandomizer randomizer)
Randomizes connection weights for the whole network using specified randomizer- Parameters:
randomizer- random weight generator to use
-
getNetworkType
public NeuralNetworkType getNetworkType()
Returns type of this network- Returns:
- network type
-
setNetworkType
public void setNetworkType(NeuralNetworkType type)
Sets type for this network- Parameters:
type- network type
-
getInputNeurons
public java.util.List<Neuron> getInputNeurons()
Returns input neurons- Returns:
- input neurons
-
getInputsCount
public int getInputsCount()
Gets number of input neurons- Returns:
- number of input neurons
-
setInputNeurons
public void setInputNeurons(java.util.List<Neuron> inputNeurons)
Sets input neurons- Parameters:
inputNeurons- array of input neurons
-
getOutputNeurons
public java.util.List<Neuron> getOutputNeurons()
Returns output neurons- Returns:
- list of output neurons
-
getOutputsCount
public int getOutputsCount()
-
setOutputNeurons
public void setOutputNeurons(java.util.List<Neuron> outputNeurons)
Sets output neurons- Parameters:
outputNeurons- output neurons collection
-
setOutputLabels
public void setOutputLabels(java.lang.String[] labels)
Sets labels for output neurons- Parameters:
labels- labels for output neurons
-
getLearningRule
public L getLearningRule()
Returns the learning algorithm of this network- Returns:
- algorithm for network training
-
setLearningRule
public void setLearningRule(L learningRule)
Sets learning algorithm for this network- Parameters:
learningRule- learning algorithm for this network
-
getWeights
public java.lang.Double[] getWeights()
Returns all network weights as an double array- Returns:
- network weights as an double array
-
setWeights
public void setWeights(double[] weights)
Sets network weights from the specified double array- Parameters:
weights- array of weights to set
-
isEmpty
public boolean isEmpty()
-
createConnection
public void createConnection(Neuron fromNeuron, Neuron toNeuron, double weightVal)
Creates connection with specified weight value between specified neurons- Parameters:
fromNeuron- neuron to connecttoNeuron- neuron to connect toweightVal- connection weight value
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
save
public void save(java.lang.String filePath)
Saves neural network into the specified file.- Parameters:
filePath- file path to save network into
-
load
public static NeuralNetwork load(java.lang.String filePath)
Deprecated. Use createFromFile method insteadLoads neural network from the specified file.- Parameters:
filePath- file path to load network from- Returns:
- loaded neural network as NeuralNetwork object
-
load
public static NeuralNetwork load(java.io.InputStream inputStream)
Loads neural network from the specified InputStream.- Parameters:
inputStream- input stream to load network from- Returns:
- loaded neural network as NeuralNetwork object
-
createFromFile
public static NeuralNetwork createFromFile(java.io.File file)
Loads and return s neural network instance from specified file- Parameters:
file- neural network file- Returns:
- neural network instance
-
createFromFile
public static NeuralNetwork createFromFile(java.lang.String filePath)
-
addPlugin
public void addPlugin(PluginBase plugin)
Adds plugin to neural network- Parameters:
plugin- neural network plugin to add
-
getPlugin
public <T extends PluginBase> T getPlugin(java.lang.Class<T> pluginClass)
Returns the requested plugin- Parameters:
pluginClass- class of the plugin to get- Returns:
- instance of specified plugin class
-
removePlugin
public void removePlugin(java.lang.Class pluginClass)
Removes the plugin with specified name- Parameters:
pluginClass- class of the plugin to remove
-
getLabel
public java.lang.String getLabel()
Get network label- Returns:
- network label
-
setLabel
public void setLabel(java.lang.String label)
Set network label- Parameters:
label- network label to set
-
addListener
public void addListener(NeuralNetworkEventListener listener)
-
removeListener
public void removeListener(NeuralNetworkEventListener listener)
-
fireNetworkEvent
public void fireNetworkEvent(NeuralNetworkEvent evt)
-
-
DMelt 3.0 © DataMelt by jWork.ORG