org.jscience.computing.ai.neurocomputing
Class PerceptronNN

java.lang.Object
  extended by org.jscience.computing.ai.neurocomputing.NeuralNetwork
      extended by org.jscience.computing.ai.neurocomputing.PerceptronNN
All Implemented Interfaces:
Visualizable

public class PerceptronNN
extends NeuralNetwork

An implementation of a perceptron.


Field Summary
protected  int correctlyClassified
          The number of correctly
protected  double learningRate
          The learning rate.
protected  double[] weights
          The weights for the inputs.
 
Fields inherited from class org.jscience.computing.ai.neurocomputing.NeuralNetwork
activation, visualization
 
Constructor Summary
PerceptronNN(int numInputs)
          Create a new instance of the Perceptron with the given number of inputs.
 
Method Summary
protected  double calculateNet(double[] inputs)
          Calculate the sum of the weighted inputs.
 int getCorrectlyClassified()
          Return the number of correctly classified training instances.
 int getCorrectlyClassified(boolean resetOnCall)
          Return the number of correctly classified training instances.
 double getWeight(int i)
          Return the perceptron weight at the given index.
 void initialize()
          Initialize the perceptron.
static void main(java.lang.String[] args)
          A simple test perceptron that learns the logic-OR gate.
 double run(double[] inputData)
          Run the network on the given set of inputs.
 double train(double[] inputData, double[] expectedOutput)
          Train the perceptron using the delta rule.
 
Methods inherited from class org.jscience.computing.ai.neurocomputing.NeuralNetwork
getVisualization, render, setActivation, setVisualization, train, train, writeImage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

weights

protected double[] weights
The weights for the inputs.


learningRate

protected double learningRate
The learning rate.


correctlyClassified

protected int correctlyClassified
The number of correctly

Constructor Detail

PerceptronNN

public PerceptronNN(int numInputs)
Create a new instance of the Perceptron with the given number of inputs. Note that the perceptron will be created with one additional weight, with a constant input of 1.0 to correspond to the bias.

Parameters:
numInputs - the number of inputs.
Method Detail

main

public static void main(java.lang.String[] args)
A simple test perceptron that learns the logic-OR gate.

Parameters:
args - the command line arguments

calculateNet

protected double calculateNet(double[] inputs)
Calculate the sum of the weighted inputs.

Parameters:
inputs - the inputs.
Returns:
the return value of the network (passed through the activation function).

run

public double run(double[] inputData)
Run the network on the given set of inputs.

Specified by:
run in class NeuralNetwork
Parameters:
inputData - the input data.
Returns:
the return value of the network.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

initialize

public void initialize()
Initialize the perceptron.

Specified by:
initialize in class NeuralNetwork

train

public double train(double[] inputData,
                    double[] expectedOutput)
Train the perceptron using the delta rule.

Specified by:
train in class NeuralNetwork
Parameters:
inputData - the input data.
expectedOutput - the expected output.
Returns:
the number of correctly classified data sets.

getCorrectlyClassified

public int getCorrectlyClassified()
Return the number of correctly classified training instances. Calling this method automatically resets the value after being called, to ease the training loop. return getCorrectlyClassified(true);

Returns:
the number of correctly classified training instances.
See Also:
getCorrectlyClassified(boolean)

getCorrectlyClassified

public int getCorrectlyClassified(boolean resetOnCall)
Return the number of correctly classified training instances.

Parameters:
resetOnCall - should correclyClassified be reset to zero after the method is called?
Returns:
the number of correctly classified training instances.

getWeight

public double getWeight(int i)
Return the perceptron weight at the given index. Note that the bias is assigned to the 0th weight.

Parameters:
i - the index of the weight to return.
Returns:
the weight.