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) )
InputFunction,
TransferFunction,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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
|
protected Layer parentLayer
protected Connection[] inputConnections
protected Connection[] outConnections
protected transient double netInput
protected transient double output
protected transient double error
protected InputFunction inputFunction
protected TransferFunction transferFunction
public Neuron()
public Neuron(InputFunction inputFunction, TransferFunction transferFunction)
inputFunction - input function for this neurontransferFunction - transfer function for this neuronpublic void calculate()
public void reset()
public void setInput(double input)
input - input value to setpublic double getNetInput()
public double getOutput()
public boolean hasInputConnections()
public boolean hasOutputConnectionTo(Neuron neuron)
public boolean hasInputConnectionFrom(Neuron neuron)
public void addInputConnection(Connection connection)
connection - input connection to addpublic void addInputConnection(Neuron fromNeuron)
fromNeuron - neuron to connect frompublic void addInputConnection(Neuron fromNeuron, double weightVal)
fromNeuron - neuron to connect fromweightVal - connection weight valueprotected void addOutputConnection(Connection connection)
connection - output connection to addpublic final Connection[] getInputConnections()
public final Connection[] getOutConnections()
protected void removeInputConnection(Connection conn)
protected void removeOutputConnection(Connection conn)
public void removeInputConnectionFrom(Neuron fromNeuron)
fromNeuron - neuron which is connected as inputpublic void removeOutputConnectionTo(Neuron toNeuron)
public void removeAllInputConnections()
public void removeAllOutputConnections()
public void removeAllConnections()
public Connection getConnectionFrom(Neuron fromNeuron)
public void setInputFunction(InputFunction inputFunction)
inputFunction - input function for this neuronpublic void setTransferFunction(TransferFunction transferFunction)
transferFunction - transfer function for this neuronpublic InputFunction getInputFunction()
public TransferFunction getTransferFunction()
public void setParentLayer(Layer parent)
parent - reference on layer in which the cell is locatedpublic Layer getParentLayer()
public Weight[] getWeights()
public double getError()
public void setError(double error)
error - neuron errorpublic void setOutput(double output)
output - value to setpublic void randomizeWeights()
public void randomizeWeights(double minWeight,
double maxWeight)
public void initializeWeights(double value)
value - the weight valuepublic void randomizeWeights(Random generator)
generator - the random number generatorpublic String getLabel()
public void setLabel(String label)
label - neuron label to setCopyright © 2013. All Rights Reserved.