org.vizzini.ai.neuralnetwork
Class AbstractNeuralNetwork

java.lang.Object
  extended by org.vizzini.ai.neuralnetwork.AbstractNeuralNetwork
All Implemented Interfaces:
Serializable, Cloneable, INeuralNetwork
Direct Known Subclasses:
DefaultNeuralNetwork, FeedForwardNetwork

abstract class AbstractNeuralNetwork
extends Object
implements INeuralNetwork

Provides base functionality for neural networks.

The network consists of an input layer, zero or more hidden layers, and an output layer. Layers before the output layer may optionally contain a bias node.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson

Constructor Summary
AbstractNeuralNetwork()
           
 
Method Summary
 void addConnector(IConnector connector)
          Add the given connector.
 void addLayer(ILayer layer)
          Add the given layer.
 void adjustWeights(int fromLayer, int toLayer, double[][] deltas)
          Adjust the given layer's weights by adding the given deltas.
 Object clone()
          Return a clone of this instance.
 void configure(Properties properties)
          Configure this object using the given properties.
 Iterator connectorIterator(String toLayerName)
          Return an iterator over the collection of connectors with the given to layer.
 boolean equals(Object object)
          Return true if the given object is equal to this.
 double[] evaluate(double[] inputs)
          Apply the given inputs and return the output of the neural network.
 void fillWeights(double value)
          Assign the given value to all weights of the neural network.
 IActivationFunction getActivationFunction(int layerIndex)
          Return the activation function.
 Properties getConfiguration()
          Return the configuration of this network.
 IConnector getConnector(ILayer fromLayer, ILayer toLayer)
          Return the connector for the given parameters.
 IConnector getConnector(int fromLayerIndex, int toLayerIndex)
          Return the connector for the given parameters.
 IConnector getConnector(String fromLayerName, String toLayerName)
          Return the connector for the given parameters.
 int getConnectorCount()
          Return the number of connectors.
protected  ConnectorCollection getConnectors()
           
 IScaler getInputScaler()
          Return the input scaler.
 ILayer getLayer(int index)
          Return the layer at the given index.
 int getLayerCount()
          Return the number of layers.
protected  List getLayers()
           
 int getMaxOutputValueIndex()
          Return the index of the output node with the maximum value.
 double getNodeInput(int layerIndex, int i)
          Return the node input value for the given parameters.
 double getNodeOutput(int layerIndex, int i)
          Return the node output value for the given parameters.
 ILayer getOutputLayer()
          Return the output layer.
 int getOutputLayerIndex()
          Return the output layer index.
 double[] getOutputs()
          Return the output layer node values.
 IScaler getOutputScaler()
          Return the output scaler.
 double getWeight(int fromLayer, int i, int toLayer, int j)
          Return the weight for the given parameters.
 double[] getWeights(int fromLayer, int i, int toLayer)
          Return the weights for the given parameters.
 int hashCode()
          Returns a hash code value for the object.
 int indexOf(ILayer layer)
          Return the index of the given layer.
 boolean isConnected(ILayer fromLayer, ILayer toLayer)
          Return true if this network has a connector from the given layer to the given layer.
 boolean isConnected(int fromIndex, int toIndex)
          Return true if this network has a connector from the given layer to the given layer.
 void randomizeWeights()
          Assign random weights to the neural network in [-0.1,0.1].
 void randomizeWeights(double range)
          Assign random weights to the neural network.
 void setActivationFunction(IActivationFunction function)
          Set the activation function.
 void setActivationFunction(int layer, IActivationFunction function)
          Set the activation function for the given layer index.
protected  void setConnectors(ConnectorCollection connectors)
           
 void setInputs(double[] inputs)
          Set the values of the input nodes.
 void setInputScaler(IScaler scaler)
          Set the input scaler.
protected  void setLayers(List layers)
           
 void setNodeInput(int layerIndex, int i, double value)
          Set the node input value for the given parameters.
 void setOutputScaler(IScaler scaler)
          Set the output scaler.
 void setWeight(int fromLayer, int i, int toLayer, int j, double weight)
          Set the weight for the given parameters.
 void store(OutputStream outputStream)
          Store the neural network to the given output stream.
 String toString()
          Return a string representation of this object.
 void zeroWeights()
          Assign zero weights to the neural network.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractNeuralNetwork

AbstractNeuralNetwork()
Method Detail

addConnector

public void addConnector(IConnector connector)
Add the given connector.

Specified by:
addConnector in interface INeuralNetwork
Parameters:
connector - Connector.
Since:
v0.3

addLayer

public void addLayer(ILayer layer)
Add the given layer.

Specified by:
addLayer in interface INeuralNetwork
Parameters:
layer - Layer.
Since:
v0.3

adjustWeights

public void adjustWeights(int fromLayer,
                          int toLayer,
                          double[][] deltas)
Adjust the given layer's weights by adding the given deltas.

Specified by:
adjustWeights in interface INeuralNetwork
Parameters:
fromLayer - From layer index, where 0=input layer, and layerCount-1=output layer.
toLayer - To layer index, where 0=input layer, and layerCount-1=output layer.
deltas - Weight deltas for the given layer.
Since:
v0.1

clone

public Object clone()
Return a clone of this instance.

Specified by:
clone in interface INeuralNetwork
Overrides:
clone in class Object
Since:
v0.1

configure

public void configure(Properties properties)
               throws InstantiationException,
                      IllegalAccessException
Configure this object using the given properties.

Specified by:
configure in interface INeuralNetwork
Throws:
InstantiationException
IllegalAccessException
Since:
v0.1

connectorIterator

public Iterator connectorIterator(String toLayerName)
Return an iterator over the collection of connectors with the given to layer.

Specified by:
connectorIterator in interface INeuralNetwork
Parameters:
toLayerName - To layer name.
Since:
v0.3

equals

public boolean equals(Object object)
Return true if the given object is equal to this.

Overrides:
equals in class Object
Parameters:
object - The object to compare.
Since:
v0.1

evaluate

public double[] evaluate(double[] inputs)
Apply the given inputs and return the output of the neural network.

Specified by:
evaluate in interface INeuralNetwork
Since:
v0.1

fillWeights

public void fillWeights(double value)
Assign the given value to all weights of the neural network.

Specified by:
fillWeights in interface INeuralNetwork
Since:
v0.3

getActivationFunction

public IActivationFunction getActivationFunction(int layerIndex)
Return the activation function.

Specified by:
getActivationFunction in interface INeuralNetwork
Parameters:
layerIndex - Layer index, where 0=input layer, and layerCount-1=output layer.
Since:
v0.1

getConfiguration

public Properties getConfiguration()
Return the configuration of this network. The input layer node count includes the bias node if used.

Specified by:
getConfiguration in interface INeuralNetwork
Since:
v0.1

getConnector

public IConnector getConnector(int fromLayerIndex,
                               int toLayerIndex)
Return the connector for the given parameters.

Specified by:
getConnector in interface INeuralNetwork
Parameters:
fromLayerIndex - From layer index.
toLayerIndex - To layer index.
Since:
v0.3

getConnector

public IConnector getConnector(ILayer fromLayer,
                               ILayer toLayer)
Return the connector for the given parameters.

Parameters:
fromLayer - From layer.
toLayer - To layer.
Since:
v0.3

getConnector

public IConnector getConnector(String fromLayerName,
                               String toLayerName)
Return the connector for the given parameters.

Parameters:
fromLayerName - From layer name.
toLayerName - To layer name.
Since:
v0.3

getConnectorCount

public int getConnectorCount()
Return the number of connectors.

Specified by:
getConnectorCount in interface INeuralNetwork
Since:
v0.3

getInputScaler

public IScaler getInputScaler()
Return the input scaler.

Specified by:
getInputScaler in interface INeuralNetwork
Since:
v0.1

getLayer

public ILayer getLayer(int index)
Return the layer at the given index.

Specified by:
getLayer in interface INeuralNetwork
Since:
v0.3

getLayerCount

public int getLayerCount()
Return the number of layers.

Specified by:
getLayerCount in interface INeuralNetwork
Since:
v0.1

getMaxOutputValueIndex

public int getMaxOutputValueIndex()
Return the index of the output node with the maximum value.

Specified by:
getMaxOutputValueIndex in interface INeuralNetwork
Since:
v0.1

getNodeInput

public double getNodeInput(int layerIndex,
                           int i)
Return the node input value for the given parameters.

Specified by:
getNodeInput in interface INeuralNetwork
Parameters:
layerIndex - Layer index, where 0=input layer, and layerCount-1=output layer.
i - Node index.
Since:
v0.3

getNodeOutput

public double getNodeOutput(int layerIndex,
                            int i)
Return the node output value for the given parameters.

Specified by:
getNodeOutput in interface INeuralNetwork
Parameters:
layerIndex - Layer index, where 0=input layer, and layerCount-1=output layer.
i - Node index.
Since:
v0.3

getOutputLayer

public ILayer getOutputLayer()
Return the output layer.

Specified by:
getOutputLayer in interface INeuralNetwork
Since:
v0.3

getOutputLayerIndex

public int getOutputLayerIndex()
Return the output layer index.

Specified by:
getOutputLayerIndex in interface INeuralNetwork
Since:
v0.3

getOutputs

public double[] getOutputs()
Return the output layer node values.

Specified by:
getOutputs in interface INeuralNetwork
Since:
v0.3

getOutputScaler

public IScaler getOutputScaler()
Return the output scaler.

Specified by:
getOutputScaler in interface INeuralNetwork
Since:
v0.1

getWeight

public double getWeight(int fromLayer,
                        int i,
                        int toLayer,
                        int j)
Return the weight for the given parameters.

Specified by:
getWeight in interface INeuralNetwork
Parameters:
fromLayer - From layer index, where 0=input layer, and layerCount-1=output layer.
i - From layer node index.
toLayer - To layer index, where 0=input layer, and layerCount-1=output layer.
j - To layer node index.
Since:
v0.1

getWeights

public double[] getWeights(int fromLayer,
                           int i,
                           int toLayer)
Return the weights for the given parameters.

Specified by:
getWeights in interface INeuralNetwork
Parameters:
fromLayer - From layer index, where 0=input layer, and layerCount-1=output layer.
i - From layer node index.
toLayer - To layer index, where 0=input layer, and layerCount-1=output layer.
Since:
v0.3

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class Object
Since:
v0.2

indexOf

public int indexOf(ILayer layer)
Return the index of the given layer.

Specified by:
indexOf in interface INeuralNetwork
Since:
v0.3

isConnected

public boolean isConnected(int fromIndex,
                           int toIndex)
Return true if this network has a connector from the given layer to the given layer.

Specified by:
isConnected in interface INeuralNetwork
Since:
v0.3

isConnected

public boolean isConnected(ILayer fromLayer,
                           ILayer toLayer)
Return true if this network has a connector from the given layer to the given layer.

Specified by:
isConnected in interface INeuralNetwork
Since:
v0.3

randomizeWeights

public void randomizeWeights()
Assign random weights to the neural network in [-0.1,0.1].

Specified by:
randomizeWeights in interface INeuralNetwork
Since:
v0.1

randomizeWeights

public void randomizeWeights(double range)
Assign random weights to the neural network.

Specified by:
randomizeWeights in interface INeuralNetwork
Parameters:
range - ±Range of random weights around zero.
Since:
v0.3

setActivationFunction

public void setActivationFunction(IActivationFunction function)
Set the activation function.

Specified by:
setActivationFunction in interface INeuralNetwork
Since:
v0.1

setActivationFunction

public void setActivationFunction(int layer,
                                  IActivationFunction function)
Set the activation function for the given layer index.

Specified by:
setActivationFunction in interface INeuralNetwork
Parameters:
layer - Layer index, where 0=input layer, and layerCount-1=output layer.
Since:
v0.3

setInputs

public void setInputs(double[] inputs)
Set the values of the input nodes.

Specified by:
setInputs in interface INeuralNetwork
Since:
v0.3

setInputScaler

public void setInputScaler(IScaler scaler)
Set the input scaler.

Specified by:
setInputScaler in interface INeuralNetwork
Since:
v0.1

setNodeInput

public void setNodeInput(int layerIndex,
                         int i,
                         double value)
Set the node input value for the given parameters.

Specified by:
setNodeInput in interface INeuralNetwork
Parameters:
layerIndex - Layer index, where 0=input layer, and layerCount-1=output layer.
i - Node index.
Since:
v0.3

setOutputScaler

public void setOutputScaler(IScaler scaler)
Set the output scaler.

Specified by:
setOutputScaler in interface INeuralNetwork
Since:
v0.1

setWeight

public void setWeight(int fromLayer,
                      int i,
                      int toLayer,
                      int j,
                      double weight)
Set the weight for the given parameters.

Specified by:
setWeight in interface INeuralNetwork
Parameters:
fromLayer - From layer index, where 0=input layer, and layerCount-1=output layer.
i - From layer node index.
toLayer - To layer index, where 0=input layer, and layerCount-1=output layer.
j - To layer node index.
weight - New weight.
Since:
v0.1

store

public void store(OutputStream outputStream)
           throws IOException
Store the neural network to the given output stream.

Specified by:
store in interface INeuralNetwork
Throws:
IOException
Since:
v0.1

toString

public String toString()
Return a string representation of this object.

Specified by:
toString in interface INeuralNetwork
Overrides:
toString in class Object
Since:
v0.1

zeroWeights

public void zeroWeights()
Assign zero weights to the neural network.

Specified by:
zeroWeights in interface INeuralNetwork
Since:
v0.3

getConnectors

protected ConnectorCollection getConnectors()
Returns:
Return connectors.

getLayers

protected List getLayers()
Returns:
Return layers.

setConnectors

protected void setConnectors(ConnectorCollection connectors)
Parameters:
connectors - the connectors to set

setLayers

protected void setLayers(List layers)
Parameters:
layers - the layers to set


Copyright © 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02