neural.net
Class Neuron

java.lang.Object
  extended by neural.net.Neuron
All Implemented Interfaces:
java.io.Serializable

public class Neuron
extends java.lang.Object
implements java.io.Serializable

Represents a single neuron within an Artificial Neural Net

Version:
1.0.0
Author:
Jonathan Reimels
See Also:
Serialized Form

Field Summary
static int OFFSET
          The offset input value
 
Constructor Summary
Neuron(int inputCount, ActivationFunction activationFunction)
          Constructor
 
Method Summary
 double fire(double[] inputs)
          Fire the neuron, ie process the input and return the output
 double getInput(int id)
          Get an input from the last set of input operated on
 int getInputCount()
          Get number of inputs for the neuron
 double getLastOutput()
          Get the last output returned by fire()
 double getWeight(int id)
          Get a weight for one of the input values
 void setWeight(int id, double weight)
          Set a weight for one of the input values
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OFFSET

public static final int OFFSET
The offset input value

See Also:
Constant Field Values
Constructor Detail

Neuron

public Neuron(int inputCount,
              ActivationFunction activationFunction)
Constructor

Parameters:
inputCount - - number of inputs the neuron accepts
activationFunction - - class implementing ActivationFunction, used to calculate activation value of neuron
Method Detail

setWeight

public void setWeight(int id,
                      double weight)
               throws java.lang.Exception
Set a weight for one of the input values

Parameters:
id - - weight to set, id must be less than the number of inputs + 1 (the offset gets a weight)
weight - - value of the weight
Throws:
java.lang.Exception - - throws an exception for invalid id

getWeight

public double getWeight(int id)
                 throws java.lang.Exception
Get a weight for one of the input values

Parameters:
id - - weight to set, id must be less than the number of inputs + 1 (the offset gets a weight)
Returns:
value of weight
Throws:
java.lang.Exception - - throws an exceptionf for invalid id

getInputCount

public int getInputCount()
Get number of inputs for the neuron

Returns:
number of inputs

getInput

public double getInput(int id)
                throws java.lang.Exception
Get an input from the last set of input operated on

Parameters:
id - - input to retrieve
Returns:
value of input
Throws:
java.lang.Exception - - throws an exception for invalid id, or if fire() has not been executed yet

getLastOutput

public double getLastOutput()
Get the last output returned by fire()

Returns:
last output value

fire

public double fire(double[] inputs)
            throws java.lang.Exception
Fire the neuron, ie process the input and return the output

Parameters:
inputs - - an array of inputs to act on
Returns:
output value of neuron
Throws:
java.lang.Exception - - throws an exception for invalid input size