public class NeuralNetwork<L extends LearningRule> extends Object implements Serializable
Base 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.
Layer
,
LearningRule
,
Serialized FormModifier and Type | Field and Description |
---|---|
protected double[] |
outputBuffer
Neural network output buffer
|
Constructor and Description |
---|
NeuralNetwork()
Creates an instance of empty neural network.
|
Modifier and Type | Method and Description |
---|---|
void |
addLayer(int index,
Layer layer)
Adds layer to specified index position in network
|
void |
addLayer(Layer layer)
Adds layer to neural network
|
void |
addListener(NeuralNetworkEventListener listener) |
void |
addPlugin(PluginBase plugin)
Adds plugin to neural network
|
void |
calculate()
Performs calculation on whole network
|
void |
createConnection(Neuron fromNeuron,
Neuron toNeuron,
double weightVal)
Creates connection with specified weight value between specified neurons
|
static NeuralNetwork |
createFromFile(File file)
Loads and return s neural network instance from specified file
|
static NeuralNetwork |
createFromFile(String filePath) |
void |
fireNetworkEvent(NeuralNetworkEvent evt) |
List<Neuron> |
getInputNeurons()
Returns input neurons
|
int |
getInputsCount()
Gets number of input neurons
|
String |
getLabel()
Get network label
|
Layer |
getLayerAt(int index)
Returns layer at specified index
|
List<Layer> |
getLayers()
Returns layers array
|
int |
getLayersCount()
Returns number of layers in network
|
L |
getLearningRule()
Returns the learning algorithm of this network
|
NeuralNetworkType |
getNetworkType()
Returns type of this network
|
double[] |
getOutput()
Returns network output vector.
|
String[] |
getOutputLabels() |
List<Neuron> |
getOutputNeurons()
Returns output neurons
|
int |
getOutputsCount() |
<T extends PluginBase> |
getPlugin(Class<T> pluginClass)
Returns the requested plugin
|
Double[] |
getWeights()
Returns all network weights as an double array
|
int |
indexOf(Layer layer)
Returns index position of the specified layer
|
boolean |
isEmpty() |
void |
learn(DataSet trainingSet)
Learn the specified training set
|
void |
learn(DataSet trainingSet,
L learningRule)
Learn the specified training set, using specified learning rule
|
static NeuralNetwork |
load(InputStream inputStream)
Loads neural network from the specified InputStream.
|
static NeuralNetwork |
load(String filePath)
Deprecated.
Use createFromFile method instead
|
void |
pauseLearning()
Pause the learning - puts learning thread in ca state.
|
void |
randomizeWeights()
Randomizes connection weights for the whole network
|
void |
randomizeWeights(double minWeight,
double maxWeight)
Randomizes connection weights for the whole network within specified
value range
|
void |
randomizeWeights(Random random)
Randomizes connection weights for the whole network using specified
random generator
|
void |
randomizeWeights(WeightsRandomizer randomizer)
Randomizes connection weights for the whole network using specified
randomizer
|
void |
removeLayer(Layer layer)
Removes specified layer from network
|
void |
removeLayerAt(int index)
Removes layer at specified index position from net
|
void |
removeListener(NeuralNetworkEventListener listener) |
void |
removePlugin(Class pluginClass)
Removes the plugin with specified name
|
void |
reset()
Resets the activation levels for whole network
|
void |
resumeLearning()
Resumes paused learning - notifies the learning rule to continue
|
void |
save(String filePath)
Saves neural network into the specified file.
|
void |
setInput(double... inputVector)
Sets network input.
|
void |
setInputNeurons(List<Neuron> inputNeurons)
Sets input neurons
|
void |
setLabel(String label)
Set network label
|
void |
setLearningRule(L learningRule)
Sets learning algorithm for this network
|
void |
setNetworkType(NeuralNetworkType type)
Sets type for this network
|
void |
setOutputLabels(String[] labels)
Sets labels for output neurons
|
void |
setOutputNeurons(List<Neuron> outputNeurons)
Sets output neurons
|
void |
setWeights(double[] weights)
Sets network weights from the specified double array
|
void |
stopLearning()
Stops learning
|
String |
toString() |
public NeuralNetwork()
public void addLayer(Layer layer)
layer
- layer to addpublic void addLayer(int index, Layer layer)
index
- index position to add layerlayer
- layer to addpublic void removeLayer(Layer layer)
layer
- layer to removeException
public void removeLayerAt(int index)
index
- int value represents index postion of layer which should be
removedpublic Layer getLayerAt(int index)
index
- layer index positionpublic int indexOf(Layer layer)
layer
- requested Layer objectpublic int getLayersCount()
public void setInput(double... inputVector) throws VectorSizeMismatchException
inputVector
- network input as double arrayVectorSizeMismatchException
public double[] getOutput()
public void calculate()
public void reset()
public void learn(DataSet trainingSet)
trainingSet
- set of training elements to learnpublic void learn(DataSet trainingSet, L learningRule)
trainingSet
- set of training elements to learnlearningRule
- instance of learning rule to use for learningpublic void stopLearning()
public void pauseLearning()
public void resumeLearning()
public void randomizeWeights()
public void randomizeWeights(double minWeight, double maxWeight)
public void randomizeWeights(Random random)
public void randomizeWeights(WeightsRandomizer randomizer)
randomizer
- random weight generator to usepublic NeuralNetworkType getNetworkType()
public void setNetworkType(NeuralNetworkType type)
type
- network typepublic int getInputsCount()
public void setInputNeurons(List<Neuron> inputNeurons)
inputNeurons
- array of input neuronspublic List<Neuron> getOutputNeurons()
public int getOutputsCount()
public void setOutputNeurons(List<Neuron> outputNeurons)
outputNeurons
- output neurons collectionpublic void setOutputLabels(String[] labels)
labels
- labels for output neuronspublic String[] getOutputLabels()
public L getLearningRule()
public void setLearningRule(L learningRule)
learningRule
- learning algorithm for this networkpublic Double[] getWeights()
public void setWeights(double[] weights)
weights
- array of weights to setpublic boolean isEmpty()
public void createConnection(Neuron fromNeuron, Neuron toNeuron, double weightVal)
fromNeuron
- neuron to connecttoNeuron
- neuron to connect toweightVal
- connection weight valuepublic void save(String filePath)
filePath
- file path to save network intopublic static NeuralNetwork load(String filePath)
filePath
- file path to load network frompublic static NeuralNetwork load(InputStream inputStream)
inputStream
- input stream to load network frompublic static NeuralNetwork createFromFile(File file)
file
- neural network filepublic static NeuralNetwork createFromFile(String filePath)
public void addPlugin(PluginBase plugin)
plugin
- neural network plugin to addpublic <T extends PluginBase> T getPlugin(Class<T> pluginClass)
pluginClass
- class of the plugin to getpublic void removePlugin(Class pluginClass)
pluginClass
- class of the plugin to removepublic String getLabel()
public void setLabel(String label)
label
- network label to setpublic void addListener(NeuralNetworkEventListener listener)
public void removeListener(NeuralNetworkEventListener listener)
public void fireNetworkEvent(NeuralNetworkEvent evt)
Copyright © 2019 Neuroph Project. All rights reserved.