com.huguesjohnson.jail.neuralNetwork
Class Neuron

java.lang.Object
  |
  +--com.huguesjohnson.jail.neuralNetwork.Neuron
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BiasNeuron, KohonenNeuron, Perceptron

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

class Neuron base class for neuron objects contains a functionality that is common to all neurons

See Also:
Serialized Form

Constructor Summary
Neuron()
          default constructor
Neuron(double[] input, double[] weights, double desiredOutput, double punishRate, double rewardRate, double errorThreshold)
          constructor
Neuron(double punishRate, double rewardRate, double errorThreshold)
          constructor
Neuron(double desiredOutput, double punishRate, double rewardRate, double errorThreshold)
          constructor
 
Method Summary
abstract  double activation()
          activation function for the neuron
abstract  void adjustWeights()
          adjust the weights for this neuron
 double getDesiredOutput()
          returns the desired output of the neuron
 boolean getDoneTraining()
          returns whether or not the neuron is done training
 double getErrorThreshold()
          returns the error threshold for the neuron
 double[] getInput()
          getInput
 double getInput(int index)
          getInput returns a specific input in the neuron
 int getInputCount()
          returns the number of inputs to this neuron
protected  double[] getInputs()
          getInputs same getInput, just around for backwards compatibility
 double getOutput()
          returns the output (activation) of this neuron
 double getPunishRate()
          returns the punish rate for the neuron
 double getRewardRate()
          returns the reward rate for the neuron
 double getWeight(int index)
          getWeight retreives a specific weight in the neuron
 int getWeightCount()
          returns the number of weights for this neuron
 double[] getWeights()
          getWeights
 double getZ()
          getZ computes a summation of all inputs*weights
 void punishWeight(int index)
          move weight closer to zero
 void randomizeWeights(int numWeights, double min, double max)
          sets random values for weights
 void rewardWeight(int index)
          move weight farther away from zero
 double run()
          run computes the value and output of the neuron
 double run(double[] input)
          run computes the value and output of the neuron
 double run(double[] input, double[] weights)
          run computes the value and output of the neuron
 void setDesiredOutput(double desiredOutput)
          sets the desired output for the neuron
 void setDoneTraining(boolean doneTraining)
          sets whether or not the neuron is done training
 void setErrorThreshold(double errorThreshold)
          sets the error threshold for the neuron
 void setInput(double[] input)
          setInput
 void setPunishRate(double punishRate)
          sets the punish rate for the neuron
 void setRewardRate(double rewardRate)
          sets the reward rate for the neuron
 void setWeight(int index, double value)
          setWeight sets a specific weight in the neuron
 void setWeights(double[] weights)
          setWeights
 java.lang.String toString()
          returns a string representation of the object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Neuron

public Neuron()
default constructor


Neuron

public Neuron(double desiredOutput,
              double punishRate,
              double rewardRate,
              double errorThreshold)
constructor

Parameters:
desiredOutput - the desired output of the neuron
punishRate - the punish rate of the neuron
rewardRate - the reward rate of the neuron
errorThreshold - the error threshold of the neuron

Neuron

public Neuron(double punishRate,
              double rewardRate,
              double errorThreshold)
constructor

Parameters:
punishRate - the punish rate of the neuron
rewardRate - the reward rate of the neuron
errorThreshold - the error threshold of the neuron

Neuron

public Neuron(double[] input,
              double[] weights,
              double desiredOutput,
              double punishRate,
              double rewardRate,
              double errorThreshold)
constructor

Parameters:
input - the input to the neuron
weights - the weights on the links to the neuron
desiredOutput - the desired output of the neuron
punishRate - the punish rate of the neuron
rewardRate - the reward rate of the neuron
errorThreshold - the error threshold of the neuron
Method Detail

getZ

public final double getZ()
getZ computes a summation of all inputs*weights

Returns:
summation of all inputs*weights

setInput

public final void setInput(double[] input)
setInput

Parameters:
input - data for neuron

setWeights

public final void setWeights(double[] weights)
setWeights

Parameters:
weights - for neuron

getWeights

public final double[] getWeights()
getWeights

Returns:
weights for neuron

getInputs

protected final double[] getInputs()
getInputs same getInput, just around for backwards compatibility

Returns:
input to neuron

getInput

public final double[] getInput()
getInput

Returns:
input to neuron

randomizeWeights

public final void randomizeWeights(int numWeights,
                                   double min,
                                   double max)
sets random values for weights

Parameters:
numWeights - number of weights to generate
min - minimum weight value
max - maximum weight value

setWeight

public final void setWeight(int index,
                            double value)
                     throws NeuronException
setWeight sets a specific weight in the neuron

Parameters:
index - index of weight to set
value - value to set
Throws:
NeuronException - if bad value is passed for index

getWeight

public final double getWeight(int index)
                       throws NeuronException
getWeight retreives a specific weight in the neuron

Parameters:
index - index of weight to get
Returns:
value of weight
Throws:
NeuronException - if bad index is passed

getInput

public final double getInput(int index)
                      throws java.lang.IndexOutOfBoundsException
getInput returns a specific input in the neuron

Parameters:
index - index of input to get
Returns:
value of input
Throws:
java.lang.IndexOutOfBoundsException - if bad index is passed

run

public final double run()
                 throws NeuronException
run computes the value and output of the neuron

Returns:
output of neuron
Throws:
NeuronException - if number of inputs and weights do not match

run

public final double run(double[] input)
                 throws NeuronException
run computes the value and output of the neuron

Parameters:
input - array of input for neuron
Returns:
output of neuron
Throws:
NeuronException - if number of inputs and weights do not match

run

public final double run(double[] input,
                        double[] weights)
                 throws NeuronException
run computes the value and output of the neuron

Parameters:
input - array of input for neuron
weights - array of weights for neuron
Returns:
output of neuron
Throws:
NeuronException - if number of inputs and weights do not match

getDoneTraining

public final boolean getDoneTraining()
returns whether or not the neuron is done training

Returns:
true if the neuron is done training

setDoneTraining

public final void setDoneTraining(boolean doneTraining)
sets whether or not the neuron is done training

Parameters:
doneTraining - new training status for neuron

setDesiredOutput

public final void setDesiredOutput(double desiredOutput)
sets the desired output for the neuron

Parameters:
desiredOutput - the desired output for the neuron

getDesiredOutput

public final double getDesiredOutput()
returns the desired output of the neuron

Returns:
desired output of the neuron

setPunishRate

public final void setPunishRate(double punishRate)
sets the punish rate for the neuron

Parameters:
punishRate - new punish rate

getPunishRate

public final double getPunishRate()
returns the punish rate for the neuron

Returns:
punish rate for the neuron

setRewardRate

public final void setRewardRate(double rewardRate)
sets the reward rate for the neuron

Parameters:
rewardRate - new reward rate

getRewardRate

public final double getRewardRate()
returns the reward rate for the neuron

Returns:
reward rate for the neuron

setErrorThreshold

public final void setErrorThreshold(double errorThreshold)
sets the error threshold for the neuron

Parameters:
errorThreshold - new error threshold

getErrorThreshold

public final double getErrorThreshold()
returns the error threshold for the neuron

Returns:
error threshold for the neuron

punishWeight

public final void punishWeight(int index)
move weight closer to zero

Parameters:
index - the index of the weight to punish

rewardWeight

public final void rewardWeight(int index)
move weight farther away from zero

Parameters:
index - the index of the weight to reward

getWeightCount

public final int getWeightCount()
returns the number of weights for this neuron

Returns:
number of weights for this neuron

getInputCount

public final int getInputCount()
returns the number of inputs to this neuron

Returns:
number of inputs to this neuron

getOutput

public final double getOutput()
returns the output (activation) of this neuron

Returns:
output (activation) of this neuron

toString

public java.lang.String toString()
returns a string representation of the object

Overrides:
toString in class java.lang.Object
Returns:
string representation of object

activation

public abstract double activation()
activation function for the neuron

Returns:
activation value

adjustWeights

public abstract void adjustWeights()
adjust the weights for this neuron