org.neuroph.core
Class Neuron

java.lang.Object
  extended by org.neuroph.core.Neuron
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BiasNeuron, DelayedNeuron, InputNeuron, InputOutputNeuron, ThresholdNeuron

public class Neuron
extends Object
implements Serializable

 Basic general neuron model according to McCulloch-Pitts neuron model.
 Different neuron models can be created by using different input and transfer functions for instances of this class,
 or by deriving from this class. The neuron is basic processing element of neural network.
 This class implements the following behaviour:
  
 output = transferFunction( inputFunction(inputConnections) )

Author:
Zoran Sevarac
See Also:
InputFunction, TransferFunction, Serialized Form

Field Summary
protected  double error
          Local error for this neuron
protected  Connection[] inputConnections
          Array of neuron's input connections (connections to this neuron)
protected  InputFunction inputFunction
          Input function for this neuron
protected  double netInput
          Total net input for this neuron.
protected  Connection[] outConnections
          Array of neuron's output connections (connections from this to other neurons)
protected  double output
          Neuron output
protected  Layer parentLayer
          Parent layer for this neuron
protected  TransferFunction transferFunction
          Transfer function for this neuron
 
Constructor Summary
Neuron()
          Creates an instance of Neuron with the weighted sum, input function and Step transfer function.
Neuron(InputFunction inputFunction, TransferFunction transferFunction)
          Creates an instance of Neuron with the specified input and transfer functions.
 
Method Summary
 void addInputConnection(Connection connection)
          Adds the specified input connection
 void addInputConnection(Neuron fromNeuron)
          Adds input connection from specified neuron
 void addInputConnection(Neuron fromNeuron, double weightVal)
          Adds input connection with the given weight, from given neuron
protected  void addOutputConnection(Connection connection)
          Adds the specified output connection
 void calculate()
          Calculates neuron's output
 Connection getConnectionFrom(Neuron fromNeuron)
          Gets input connection from the specified neuron * @param fromNeuron neuron connected to this neuron as input
 double getError()
          Returns error for this neuron.
 Connection[] getInputConnections()
          Returns input connections for this neuron
 InputFunction getInputFunction()
          Returns input function
 String getLabel()
          Returns label for this neuron
 double getNetInput()
          Returns total net input
 Connection[] getOutConnections()
          Returns output connections from this neuron
 double getOutput()
          Returns neuron's output
 Layer getParentLayer()
          Returns reference to parent layer for this neuron
 TransferFunction getTransferFunction()
          Returns transfer function
 Weight[] getWeights()
          Returns weights vector of input connections
 boolean hasInputConnectionFrom(Neuron neuron)
           
 boolean hasInputConnections()
          Returns true if there are input connections for this neuron, false otherwise
 boolean hasOutputConnectionTo(Neuron neuron)
           
 void initializeWeights(double value)
          Initialize weights for all input connections to specified value
 void randomizeWeights()
          Randomize all input weights
 void randomizeWeights(double minWeight, double maxWeight)
          Randomize all input weights within specified value range
 void randomizeWeights(Random generator)
          Randomize weights for all input connections to using random number generator
 void removeAllConnections()
           
 void removeAllInputConnections()
           
 void removeAllOutputConnections()
           
protected  void removeInputConnection(Connection conn)
           
 void removeInputConnectionFrom(Neuron fromNeuron)
          Removes input connection which is connected to specified neuron
protected  void removeOutputConnection(Connection conn)
           
 void removeOutputConnectionTo(Neuron toNeuron)
           
 void reset()
          Sets input and output activation levels to zero
 void setError(double error)
          Sets error for this neuron.
 void setInput(double input)
          Sets neuron's input
 void setInputFunction(InputFunction inputFunction)
          Sets input function
 void setLabel(String label)
          Sets the label for this neuron
 void setOutput(double output)
          Sets this neuron output
 void setParentLayer(Layer parent)
          Sets reference to parent layer for this neuron (layer in which the neuron is located)
 void setTransferFunction(TransferFunction transferFunction)
          Sets transfer function
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parentLayer

protected Layer parentLayer
Parent layer for this neuron


inputConnections

protected Connection[] inputConnections
Array of neuron's input connections (connections to this neuron)


outConnections

protected Connection[] outConnections
Array of neuron's output connections (connections from this to other neurons)


netInput

protected transient double netInput
Total net input for this neuron. Represents total input for this neuron received from input function.


output

protected transient double output
Neuron output


error

protected transient double error
Local error for this neuron


inputFunction

protected InputFunction inputFunction
Input function for this neuron


transferFunction

protected TransferFunction transferFunction
Transfer function for this neuron

Constructor Detail

Neuron

public Neuron()
Creates an instance of Neuron with the weighted sum, input function and Step transfer function. This is the original McCulloch-Pitts neuron model.


Neuron

public Neuron(InputFunction inputFunction,
              TransferFunction transferFunction)
Creates an instance of Neuron with the specified input and transfer functions.

Parameters:
inputFunction - input function for this neuron
transferFunction - transfer function for this neuron
Method Detail

calculate

public void calculate()
Calculates neuron's output


reset

public void reset()
Sets input and output activation levels to zero


setInput

public void setInput(double input)
Sets neuron's input

Parameters:
input - input value to set

getNetInput

public double getNetInput()
Returns total net input

Returns:
total net input

getOutput

public double getOutput()
Returns neuron's output

Returns:
neuron output

hasInputConnections

public boolean hasInputConnections()
Returns true if there are input connections for this neuron, false otherwise

Returns:
true if there is input connection, false otherwise

hasOutputConnectionTo

public boolean hasOutputConnectionTo(Neuron neuron)

hasInputConnectionFrom

public boolean hasInputConnectionFrom(Neuron neuron)

addInputConnection

public void addInputConnection(Connection connection)
Adds the specified input connection

Parameters:
connection - input connection to add

addInputConnection

public void addInputConnection(Neuron fromNeuron)
Adds input connection from specified neuron

Parameters:
fromNeuron - neuron to connect from

addInputConnection

public void addInputConnection(Neuron fromNeuron,
                               double weightVal)
Adds input connection with the given weight, from given neuron

Parameters:
fromNeuron - neuron to connect from
weightVal - connection weight value

addOutputConnection

protected void addOutputConnection(Connection connection)
Adds the specified output connection

Parameters:
connection - output connection to add

getInputConnections

public final Connection[] getInputConnections()
Returns input connections for this neuron

Returns:
input connections of this neuron

getOutConnections

public final Connection[] getOutConnections()
Returns output connections from this neuron

Returns:
output connections from this neuron

removeInputConnection

protected void removeInputConnection(Connection conn)

removeOutputConnection

protected void removeOutputConnection(Connection conn)

removeInputConnectionFrom

public void removeInputConnectionFrom(Neuron fromNeuron)
Removes input connection which is connected to specified neuron

Parameters:
fromNeuron - neuron which is connected as input

removeOutputConnectionTo

public void removeOutputConnectionTo(Neuron toNeuron)

removeAllInputConnections

public void removeAllInputConnections()

removeAllOutputConnections

public void removeAllOutputConnections()

removeAllConnections

public void removeAllConnections()

getConnectionFrom

public Connection getConnectionFrom(Neuron fromNeuron)
Gets input connection from the specified neuron * @param fromNeuron neuron connected to this neuron as input


setInputFunction

public void setInputFunction(InputFunction inputFunction)
Sets input function

Parameters:
inputFunction - input function for this neuron

setTransferFunction

public void setTransferFunction(TransferFunction transferFunction)
Sets transfer function

Parameters:
transferFunction - transfer function for this neuron

getInputFunction

public InputFunction getInputFunction()
Returns input function

Returns:
input function

getTransferFunction

public TransferFunction getTransferFunction()
Returns transfer function

Returns:
transfer function

setParentLayer

public void setParentLayer(Layer parent)
Sets reference to parent layer for this neuron (layer in which the neuron is located)

Parameters:
parent - reference on layer in which the cell is located

getParentLayer

public Layer getParentLayer()
Returns reference to parent layer for this neuron

Returns:
parent layer for this neuron

getWeights

public Weight[] getWeights()
Returns weights vector of input connections

Returns:
weights vector of input connections

getError

public double getError()
Returns error for this neuron. This is used by supervised learing rules.

Returns:
error for this neuron which is set by learning rule

setError

public void setError(double error)
Sets error for this neuron. This is used by supervised learing rules.

Parameters:
error - neuron error

setOutput

public void setOutput(double output)
Sets this neuron output

Parameters:
output - value to set

randomizeWeights

public void randomizeWeights()
Randomize all input weights


randomizeWeights

public void randomizeWeights(double minWeight,
                             double maxWeight)
Randomize all input weights within specified value range


initializeWeights

public void initializeWeights(double value)
Initialize weights for all input connections to specified value

Parameters:
value - the weight value

randomizeWeights

public void randomizeWeights(Random generator)
Randomize weights for all input connections to using random number generator

Parameters:
generator - the random number generator

getLabel

public String getLabel()
Returns label for this neuron

Returns:
label for this neuron

setLabel

public void setLabel(String label)
Sets the label for this neuron

Parameters:
label - neuron label to set


Copyright © 2012. All Rights Reserved.