public class Neuron extends Object implements Serializable, Cloneable
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 FormModifier and Type | Field and Description |
---|---|
protected double |
delta
Local error (delta) for this neuron *
|
protected List<Connection> |
inputConnections
Collection of neuron's input connections (connections to this neuron)
|
protected InputFunction |
inputFunction
Input function for this neuron
|
protected List<Connection> |
outConnections
Collection 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 double |
totalInput
Total net input for this neuron.
|
protected TransferFunction |
transferFunction
Transfer function for this neuron
|
Constructor and Description |
---|
Neuron()
Creates an instance of Neuron with default settings: 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
|
Object |
clone() |
Connection |
getConnectionFrom(Neuron fromNeuron)
Gets input connection from the specified neuron * @param fromNeuron
neuron connected to this neuron as input
|
double |
getDelta()
Returns delta (error) for this neuron.
|
List<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
|
List<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)
Check the connection from neuron
|
boolean |
hasInputConnections()
Returns true if there are input connections for this neuron, false
otherwise
|
boolean |
hasOutputConnectionTo(Neuron toNeuron)
Check the connection to neuron
|
void |
initializeWeights(double value)
Initialize weights for all input connections to specified value
|
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 |
setDelta(double delta)
Sets delta 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 List<Connection> inputConnections
protected List<Connection> outConnections
protected transient double totalInput
protected transient double output
protected transient double delta
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 toNeuron)
neuron
- neuron connection to be checkedpublic boolean hasInputConnectionFrom(Neuron neuron)
neuron
- neuron connection to be checkedpublic 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 List<Connection> getInputConnections()
public final List<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 getDelta()
public void setDelta(double delta)
delta
- neuron deltapublic void setOutput(double output)
output
- value to setpublic void initializeWeights(double value)
value
- the weight valuepublic String getLabel()
public void setLabel(String label)
label
- neuron label to setpublic Object clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
Copyright © 2019 Neuroph Project. All rights reserved.