Neuroph

org.neuroph.core
Class NeuralNetwork

java.lang.Object
  extended by java.util.Observable
      extended by org.neuroph.core.NeuralNetwork
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable
Direct Known Subclasses:
Adaline, CompetitiveNetwork, Hopfield, Kohonen, MaxNet, MultiLayerPerceptron, NeuroFuzzyReasoner, Perceptron, RbfNetwork, SupervisedHebbianNetwork, UnsupervisedHebbianNetwork

public class NeuralNetwork
extends java.util.Observable
implements java.lang.Runnable, java.io.Serializable

 The NeuralNetwork class is the base class for artificial neural networks. It provides generic structure and functionality
 for the neural networks. Neural network contains a collection of neuron getLayersIterator 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

Field Summary
private  java.util.Vector<Neuron> inputNeurons
          Reference to network input neurons
private  java.util.Vector<Layer> layers
          Neural network getLayersIterator
private  LearningRule learningRule
          Learning rule for this network
private  java.lang.Thread learningThread
          Separate thread for learning rule
private  java.util.Vector<Neuron> outputNeurons
          Reference to newtwork output neurons
private  java.util.Map<java.lang.String,PluginBase> plugins
          Plugins collection
private static long serialVersionUID
          The class fingerprint that is set to indicate serialization compatibility with a previous version of the class.
private  NeuralNetworkType type
          Network type id (see neuroph.util.NeuralNetworkType)
 
Constructor Summary
NeuralNetwork()
          Creates an instance of empty neural network.
 
Method Summary
 void addLayer(int idx, Layer layer)
          Adds layer to specified index position in network
 void addLayer(Layer layer)
          Adds layer to neural network
 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
 java.util.Vector<Neuron> getInputNeurons()
          Returns reference to input neurons Vector.
 Layer getLayerAt(int idx)
          Returns layer at specified index
 java.util.Vector<Layer> getLayers()
          Returns getLayersIterator Vector collection
 int getLayersCount()
          Returns number of layers in network
 java.util.Iterator<Layer> getLayersIterator()
          Returns interface for iterating layers
 LearningRule getLearningRule()
          Returns learning algorithm
 NeuralNetworkType getNetworkType()
          Returns network type
 java.util.Vector<java.lang.Double> getOutput()
          Returns network output Vector.
 java.util.Vector<Neuron> getOutputNeurons()
          Returns reference to output neurons Vector.
 PluginBase getPlugin(java.lang.String pluginName)
          Returns the requested plugin
 int indexOf(Layer layer)
          Returns index position of the specified layer
 void learn(TrainingSet trainingSetToLearn)
          Trains the network to leran the specified training set.
static NeuralNetwork load(java.lang.String filePath)
          Loads neural network from the specified file.
 void notifyChange()
          Notifies observers about some change
 void randomizeWeights()
          Randomize all network weights
 void removeLayer(Layer layer)
          Removes specified layer from network
 void removeLayerAt(int idx)
          Removes layer at specified index position from net
 void removePlugin(java.lang.String pluginName)
          Removes the specified plugin
 void reset()
          Resets the activation levels for whole network
 void run()
          Implementation of Runnable interface for calculating network in the separate thread.
 void save(java.lang.String filePath)
          Saves neural network into the specified file.
 void setInput(java.util.Vector<java.lang.Double> inputVector)
          Set network input.
 void setInputNeurons(java.util.Vector<Neuron> inputNeurons)
          Sets reference to input neurons Vector
 void setLearningRule(LearningRule learningRule)
          Sets learning algorithm for this network
 void setNetworkType(NeuralNetworkType type)
          Sets network type
 void setOutputNeurons(java.util.Vector<Neuron> outputNeurons)
          Sets reference to output neurons Vector.
 void stopLearning()
          Stops learning
 java.lang.String toString()
           
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
The class fingerprint that is set to indicate serialization compatibility with a previous version of the class.

See Also:
Constant Field Values

type

private NeuralNetworkType type
Network type id (see neuroph.util.NeuralNetworkType)


layers

private java.util.Vector<Layer> layers
Neural network getLayersIterator


inputNeurons

private java.util.Vector<Neuron> inputNeurons
Reference to network input neurons


outputNeurons

private java.util.Vector<Neuron> outputNeurons
Reference to newtwork output neurons


learningRule

private LearningRule learningRule
Learning rule for this network


learningThread

private transient java.lang.Thread learningThread
Separate thread for learning rule


plugins

private java.util.Map<java.lang.String,PluginBase> plugins
Plugins collection

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 idx,
                     Layer layer)
Adds layer to specified index position in network

Parameters:
idx - index position to add layer
layer - layer to add

removeLayer

public void removeLayer(Layer layer)
Removes specified layer from network

Parameters:
layer - layer to remove

removeLayerAt

public void removeLayerAt(int idx)
Removes layer at specified index position from net

Parameters:
idx - int value represents index postion of layer which should be removed

getLayersIterator

public java.util.Iterator<Layer> getLayersIterator()
Returns interface for iterating layers

Returns:
iterator interface for network getLayersIterator

getLayers

public java.util.Vector<Layer> getLayers()
Returns getLayersIterator Vector collection

Returns:
getLayersIterator Vector collection

getLayerAt

public Layer getLayerAt(int idx)
Returns layer at specified index

Parameters:
idx - 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(java.util.Vector<java.lang.Double> inputVector)
Set network input. Input Vector is collection of Double values.

Parameters:
inputVector - network input vector

getOutput

public java.util.Vector<java.lang.Double> getOutput()
Returns network output Vector. Output Vector is 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


run

public void run()
Implementation of Runnable interface for calculating network in the separate thread.

Specified by:
run in interface java.lang.Runnable

learn

public void learn(TrainingSet trainingSetToLearn)
Trains the network to leran the specified training set.

Parameters:
trainingSetToLearn - set of training elements to learn

stopLearning

public void stopLearning()
Stops learning


randomizeWeights

public void randomizeWeights()
Randomize all network weights


getNetworkType

public NeuralNetworkType getNetworkType()
Returns network type

Returns:
network type

setNetworkType

public void setNetworkType(NeuralNetworkType type)
Sets network type

Parameters:
type - network type

getInputNeurons

public java.util.Vector<Neuron> getInputNeurons()
Returns reference to input neurons Vector.

Returns:
input neurons Vector

setInputNeurons

public void setInputNeurons(java.util.Vector<Neuron> inputNeurons)
Sets reference to input neurons Vector

Parameters:
inputNeurons - input neurons collection

getOutputNeurons

public java.util.Vector<Neuron> getOutputNeurons()
Returns reference to output neurons Vector.

Returns:
output neurons Vector

setOutputNeurons

public void setOutputNeurons(java.util.Vector<Neuron> outputNeurons)
Sets reference to output neurons Vector.

Parameters:
outputNeurons - output neurons collection

getLearningRule

public LearningRule getLearningRule()
Returns learning algorithm

Returns:
algorithm for network training

setLearningRule

public void setLearningRule(LearningRule learningRule)
Sets learning algorithm for this network

Parameters:
learningRule - learning algorithm for this network

notifyChange

public void notifyChange()
Notifies observers about some change


createConnection

public void createConnection(Neuron fromNeuron,
                             Neuron toNeuron,
                             double weightVal)
Creates connection with specified weight value, between specified neurons

Parameters:
connection - input connection to add

toString

public java.lang.String toString()
Overrides:
toString in class java.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)
Loads neural network from the specified file.

Parameters:
filePath - file path to load network from
Returns:
loaded neural network as NeuralNetwork object

addPlugin

public void addPlugin(PluginBase plugin)
Adds plugin to neural network

Parameters:
plugin - neural network plugin to add

getPlugin

public PluginBase getPlugin(java.lang.String pluginName)
Returns the requested plugin

Parameters:
pluginName - name of the plugin to get
Returns:
plugin with specified name

removePlugin

public void removePlugin(java.lang.String pluginName)
Removes the specified plugin

Parameters:
pluginName - name of the plugin to remove

Neuroph