public class Neuron extends BrainPart implements java.lang.Comparable
NOTE:
- the actual worker methods of links (adding, removing) are found in the Link class.
- for persistence, the default methods in the Boone class work.
- A Neuron doesn't contain a reference to the NeuralNet it is contained by.
| Modifier and Type | Field and Description |
|---|---|
protected double |
errorSignal
The error signal used for training.
|
protected double |
externalInput
the external input signal, meant for the input of input neurons.
|
protected double |
input
Current input signal.
|
protected boolean |
inputNeuron
Indicates an input neuron.
|
protected int |
layer
The layer number.
|
protected double |
linkInput
The sum of the inputs from the links to this neuron.
|
protected java.util.ArrayList<Link> |
links
All the neuron's links.
|
protected double |
output
The current neuron output.
|
protected boolean |
outputNeuron
Indicates an output neuron.
|
protected Position |
position
The neuron position.
|
protected boolean |
usingBias
Indicates usage of bias value.
|
activationFn, name, NO_ID, weight| Constructor and Description |
|---|
Neuron()
Creates a default Neuron using bias and Sigmoid activation.
|
Neuron(boolean in,
boolean out,
boolean bias)
Creates a default Neuron with the given parameters.
|
Neuron(Function function)
Creates a default Neuron using bias and the given activation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLinkInput(Link link)
Adds a link signal to the neuron's input.
|
void |
addToBias(double deltaBias)
Adds the given value to the bias value.
|
void |
calculate()
Propagate the neuron input to the neuron output.
|
Neuron |
clone()
Returns a semi-deep clone of this neuron.
|
int |
compareTo(java.lang.Object o)
Compares the neurons with respect to the layer number.
|
void |
fromXML(org.jdom2.Element element)
Reads attributes from XML tree.
|
double |
getBias()
Returns the bias value.
|
double |
getErrorSignal()
Returns the current error signal.
|
double |
getExternalInput() |
double |
getInput()
Return the neuron input, which is the sum of
externalInput,
linkInput, and BrainPart.weight (if usingBias is enabled). |
Link |
getInputLink(int index)
Returns the input link of given index.
|
int |
getInputLinkCount()
Returns the number of input links.
|
int |
getLayer()
Returns the layer number of the neuron.
|
Link |
getLink(int index)
get a link
|
int |
getLinkCount()
Returns the number of links of this neuron.
|
double |
getLinkInput()
Return the value of the linkInput; please see above.
|
java.util.ArrayList<Link> |
getLinks()
Get all the input and output links.
|
Link |
getLinkTo(Neuron other)
Returns the link connecting this neuron to the given other neuron, which may also be the same neuron.
|
double |
getOutput()
Returns the current output value of this neuron.
|
Link |
getOutputLink(int index)
Returns the output link of given index.
|
int |
getOutputLinkCount()
Returns the number of output links.
|
Position |
getPosition()
Returns the position of the neuron.
|
boolean |
isHiddenNeuron()
Return true iff the neuron is neither input nor output neuron.
|
boolean |
isInputNeuron()
Indicates the input neuron state.
|
boolean |
isOutputNeuron() |
boolean |
isUsingBias() |
void |
propagateOutput()
Sends the neuron's activation onto the link.
|
void |
reset()
Resets internal neuron attributes.
|
void |
setBias(double bias)
Sets the bias value.
|
void |
setErrorSignal(double errorSignal)
Sets the error signal.
|
void |
setExternalInput(double externalInput)
Set the neuron's external input, e.g.
|
void |
setInput(double input)
Sets the current input value of the neuron.
|
void |
setInputNeuron(boolean inputNeuron)
define whether this neuron is an input neuron.
|
void |
setLayer(int layer)
Sets the layer number.
|
void |
setLinkInput(double linkInput)
Sets the neuron's link input.
|
void |
setOutput(double output)
Set the current output value of this neuron.
|
void |
setOutputNeuron(boolean outputNeuron)
define whether this neuron is an output neuron.
|
void |
setPosition(Position position)
Sets the neuron position.
|
void |
setUsingBias(boolean usingBias) |
java.lang.String |
toString()
Returns a string representation of the neuron.
|
org.jdom2.Element |
toXML(org.jdom2.Element element)
Writes attributes to XML tree.
|
addGradient, addToWeight, getAccu, getActivationFn, getGradient, getID, getLastGradient, getName, getUniqueID, getWeight, isTrainable, randomize, randomize, setAccu, setActivationFn, setGradient, setID, setLastGradient, setName, setTrainable, setWeightprotected Position position
protected boolean inputNeuron
protected boolean outputNeuron
protected int layer
protected boolean usingBias
protected double errorSignal
protected double externalInput
protected double linkInput
addLinkInput(boone.Link) method. protected double input
calculate() method by adding the linkInput and the
externalInput values.protected double output
protected java.util.ArrayList<Link> links
public Neuron()
public Neuron(Function function)
function - the activation functionpublic Neuron(boolean in,
boolean out,
boolean bias)
in - an input neuronout - an output neuronbias - true, if using biaspublic Neuron clone()
public int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparableo - a neuronpublic void calculate()
The neuron input (externalInput and linkInput) are already filled with the input
values at this time.
Doesn't calculate the output links; see propagateOutput() instead.
Calculates the following values for this neuron: input,
and output. Resets the linkInput to zero.
public void propagateOutput()
Calls Link.propagate() for each output
link of this neuron.
public boolean isInputNeuron()
public void setInputNeuron(boolean inputNeuron)
public boolean isOutputNeuron()
public void setOutputNeuron(boolean outputNeuron)
public boolean isHiddenNeuron()
public Position getPosition()
public void setPosition(Position position)
position - the positionpublic int getLayer()
public void setLayer(int layer)
layer - the numberpublic double getExternalInput()
public void setExternalInput(double externalInput)
NeuralNet.setInput(double[]).
Please also note that this attribute may be reset to zero on network evaluation, if
the NeuralNet.setZeroInputAfterFirstCycle(boolean) flag is set to true (e.g. for
Hopfield networks).
externalInput - the external input valuepublic double getInput()
externalInput,
linkInput, and BrainPart.weight (if usingBias is enabled).
Calculated in the calculate() method.public void setInput(double input)
calculate(), this value is calculated as the sum of externalInput,
linkInput, and BrainPart.weight (the latter only if usingBias is enabled),
and thus overwritten on network calculation.input - New value of property input.public double getOutput()
public void setOutput(double output)
output - New value of property output.public double getBias()
public void setBias(double bias)
bias - the biaspublic void addToBias(double deltaBias)
deltaBias - the bias change valuepublic double getErrorSignal()
public void setErrorSignal(double errorSignal)
errorSignal - a value used for trainingpublic void setLinkInput(double linkInput)
linkInput - the valuepublic void addLinkInput(Link link)
link - the link on which the signal is sentpublic double getLinkInput()
public boolean isUsingBias()
public void setUsingBias(boolean usingBias)
usingBias - whether the neuron should use the bias value.public int getLinkCount()
public Link getLink(int index)
public java.util.ArrayList<Link> getLinks()
public Link getLinkTo(Neuron other)
other - the other neuron possibly linked to this neuronpublic int getInputLinkCount()
public Link getInputLink(int index)
public int getOutputLinkCount()
public Link getOutputLink(int index)
public void fromXML(org.jdom2.Element element)
public org.jdom2.Element toXML(org.jdom2.Element element)