org.jscience.computing.ai.neurocomputing
Class NeuralNetwork

java.lang.Object
  extended by org.jscience.computing.ai.neurocomputing.NeuralNetwork
All Implemented Interfaces:
Visualizable
Direct Known Subclasses:
FeedForwardNN, KohonenNN, PerceptronNN

public abstract class NeuralNetwork
extends java.lang.Object
implements Visualizable

A neural network framework class. The class is meant to help create simple neural networks, such as perceptrons and self-organizing networks.


Field Summary
protected  Activation activation
          The activation function.
protected  Visualizable visualization
          Allows for a visualizer to be assigned to a neural network.
 
Constructor Summary
NeuralNetwork()
           
 
Method Summary
 Visualizable getVisualization()
          Return the current visualization.
abstract  void initialize()
          Initialize the neural network.
 void render(java.awt.Graphics g, int width, int height)
          Render the neural network using the assigned visualization.
abstract  double run(double[] inputData)
          Run the neural network on the given inputs.
 void setActivation(Activation ac)
          Set the activation function.
 void setVisualization(Visualizable vis)
          Set the visualization to use.
 double train(double[] inputData)
          This method is provided as a helper for networks that have no expected output, such as unsupervised networks.
 double train(double[] inputData, double expectedOutput)
          This method is provided as a helper for networks that only have one output, therefore only one expected output.
abstract  double train(double[] inputData, double[] expectedOutput)
          Train the neural network on the given training data.
 void writeImage(java.lang.String s, int width, int height)
          Write an image of the neural network using the assigned visualization.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

visualization

protected Visualizable visualization
Allows for a visualizer to be assigned to a neural network. This may be a data plotter, a bitmapped representation of the neural network etc.


activation

protected Activation activation
The activation function.

Constructor Detail

NeuralNetwork

public NeuralNetwork()
Method Detail

initialize

public abstract void initialize()
                         throws NeuralNetworkException
Initialize the neural network.

Throws:
NeuralNetworkException - This

train

public abstract double train(double[] inputData,
                             double[] expectedOutput)
                      throws NeuralNetworkException
Train the neural network on the given training data.

Parameters:
inputData - the input data.
expectedOutput - the expect output.
Returns:
a double value. This actual interpretation of this return is class-dependent.
Throws:
NeuralNetworkException - if an error occurs with training, this method should throw a NeuralNetworkException.

train

public double train(double[] inputData,
                    double expectedOutput)
             throws NeuralNetworkException
This method is provided as a helper for networks that only have one output, therefore only one expected output. The method is defined as: public double train(double[] inputData, double expectedOutput) throws NeuralNetworkException {return train(inputData, new double[] { expectedOutput }); }

Parameters:
inputData - the input data.
expectedOutput - the expected output.
Returns:
the value returned by train(double[], double[]).
Throws:
NeuralNetworkException - the exception thrown if any training errors occur.
See Also:
train(double[],double[])

train

public double train(double[] inputData)
             throws NeuralNetworkException
This method is provided as a helper for networks that have no expected output, such as unsupervised networks. The method is defined as: public double train(double[] inputData) throws NeuralNetworkException {return train(inputData, null); }

Parameters:
inputData - the input data.
Returns:
the value returned by train(double[], double[]).
Throws:
NeuralNetworkException - the exception thrown if any training errors occur.

run

public abstract double run(double[] inputData)
                    throws NeuralNetworkException
Run the neural network on the given inputs.

Parameters:
inputData - the input data.
Returns:
the returned value of the neural network.
Throws:
NeuralNetworkException - an exception is thrown if an error occurs.

setActivation

public void setActivation(Activation ac)
Set the activation function.

Parameters:
ac - the activation function.

render

public void render(java.awt.Graphics g,
                   int width,
                   int height)
Render the neural network using the assigned visualization.

Specified by:
render in interface Visualizable
Parameters:
g - the graphics context.
width - the width of the graphics context.
height - the height of the graphics context.

writeImage

public void writeImage(java.lang.String s,
                       int width,
                       int height)
Write an image of the neural network using the assigned visualization.

Specified by:
writeImage in interface Visualizable
Parameters:
s - the filename of the image to write.
width - the width of the image.
height - the height of the image.

getVisualization

public Visualizable getVisualization()
Return the current visualization.

Returns:
the visualization currently assigned.

setVisualization

public void setVisualization(Visualizable vis)
Set the visualization to use.

Parameters:
vis - the visualization class to use.