public class NeuralNet extends java.lang.Object implements Storable, java.lang.Cloneable
Use NetFactory to create NeuralNets conveniently.
| Modifier and Type | Field and Description |
|---|---|
static int |
FEEDFORWARD
A feed-forward network.
|
protected IOFilter |
filter
The IO filter.
|
protected NeuronList |
inputNeurons
The input neurons.
|
protected java.util.List<Layer> |
layers
The ordered layers of the network.
|
protected java.util.ArrayList<Link> |
links
All the links of the network.
|
protected int |
maxCycles
The maximal number of cycles
|
protected NeuronList |
neurons
All the neurons of the network.
|
protected NeuronList |
outputNeurons
The output neurons.
|
java.util.Properties |
props
Some custom properties.
|
static int |
RECURRENT
A recurrent network.
|
protected int |
topology
The network topology.
|
protected Trainer |
trainer
The trainer for this network.
|
static int |
UNKNOWN
The topology is not determined.
|
protected boolean |
zeroInputAfterFirstCycle
Reset the external input of the input neurons to zero after the first cycle
when innervating the network? Probably only useful for recurrent networks,
where the internal per-neuron feed-back should take over
(see
Neuron.loopOutputToInput). |
| Constructor and Description |
|---|
NeuralNet()
Constructs the net with a default Boone IO filter.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addLayer(Layer layer)
Adds the layer, the neurons of the layer and their input links to this net.
|
void |
addLink(Link link)
Adds a link.
|
void |
addNeuron(Neuron neuron)
Add a neuron to our list.
|
NeuralNet |
clone()
Clone method for this NeuralNet.
|
void |
fromXML(org.jdom2.Element element)
Loads the network attributes from XML.
|
IOFilter |
getFilter()
Returns the IO filter.
|
int |
getHiddenNeuronCount()
Return the number of hidden neurons, that is, neurons which are neither input
nor output neurons.
|
Neuron |
getInputNeuron(int num) |
int |
getInputNeuronCount()
Returns the number of input neurons.
|
Link |
getLink(int num)
Returns a specific link in the net.
|
int |
getLinkCount() |
Link |
getLinkID(long id)
Returns the link with the given ID.
|
int |
getMaxCycles() |
Neuron |
getNeuron(int num) |
int |
getNeuronCount()
Returns the number of neurons in this net.
|
Neuron |
getNeuronID(long id)
Returns the neuron with the given ID.
|
int |
getNeuronIndex(Neuron neuron) |
double[] |
getOutput(double[] outputs)
Extract the output pattern from the network.
|
Neuron |
getOutputNeuron(int index)
Returns a specific output neuron in the network.
|
int |
getOutputNeuronCount() |
int |
getOutputNeuronIndex(Neuron output)
Returns the index of the given output neuron in the internal list.
|
int |
getTopology()
Returns the topology of the net.
|
Trainer |
getTrainer()
Returns the trainer of the net.
|
boolean |
getZeroInputAfterFirstCycle()
Return whether the NeuralNet zeroes out the external input of the input neurons
after the first evaluation cycle.
|
void |
innervate()
Innervate the network, i.e.
|
void |
linkNet(NeuralNet other)
Links another net to this net (by appending at end).
|
static NeuralNet |
load(java.io.File file,
IOFilter filter)
Loads a NeuralNet from the given file using the set file filter.
|
void |
randomize()
Randomizes the network parameters to some meaningful values.
|
boolean |
removeLink(Link link)
remove a link from our network.
|
boolean |
removeNeuron(Neuron neuron)
Removes a neuron and updates the associated links, but no link lists.
|
void |
replaceLink(Link oldLink,
Link newLink)
replace a link with another.
|
void |
replaceNeuron(Neuron oldNeuron,
Neuron newNeuron)
Replace a neuron with another.
|
void |
save(java.io.File file)
Save a NeuralNet to the given file, in the Boone XNet format, using the IOFilter class.
|
void |
setFilter(IOFilter filter)
Sets the IO filter.
|
void |
setInput(double[] values)
Load the input pattern into the network.
|
void |
setInput(java.util.List<java.lang.Double> values)
Load the input pattern into the network.
|
void |
setMaxCycles(int maxCycles) |
void |
setTopology(int topology)
Sets the topology of the net.
|
void |
setTrainer(Trainer trainer)
Assigns a trainer to the network and prepares the network for training.
|
void |
setZeroInputAfterFirstCycle(boolean makeZero)
Define whether to reset the external input of the input neurons to zero
after the first cycle when innervating the network.
|
java.lang.String |
toString()
convert the net to a string (multi-line).
|
org.jdom2.Element |
toXML(org.jdom2.Element element)
Writes attributes to XML.
|
public static final int UNKNOWN
public static final int FEEDFORWARD
public static final int RECURRENT
protected int topology
protected java.util.List<Layer> layers
protected NeuronList neurons
protected NeuronList inputNeurons
protected NeuronList outputNeurons
protected java.util.ArrayList<Link> links
protected Trainer trainer
protected int maxCycles
protected boolean zeroInputAfterFirstCycle
Neuron.loopOutputToInput).Default: false.
protected IOFilter filter
public java.util.Properties props
public int getTopology()
public void setTopology(int topology)
topology - the topology valuepublic IOFilter getFilter()
public void setFilter(IOFilter filter)
filter - the IO filterpublic int getNeuronCount()
public Neuron getNeuron(int num)
public int getNeuronIndex(Neuron neuron)
public Neuron getNeuronID(long id)
id - the neuron IDpublic int getInputNeuronCount()
public Neuron getInputNeuron(int num)
public int getOutputNeuronCount()
public Neuron getOutputNeuron(int index)
index - the indexpublic int getOutputNeuronIndex(Neuron output)
output - an output neuronpublic int getHiddenNeuronCount()
public void addNeuron(Neuron neuron)
neuron - the neuron to addpublic void addLayer(Layer layer)
layer - the layerpublic void replaceNeuron(Neuron oldNeuron, Neuron newNeuron)
public boolean removeNeuron(Neuron neuron)
public int getLinkCount()
public Link getLink(int num)
public Link getLinkID(long id)
id - the link IDpublic void addLink(Link link)
link - a linkpublic void replaceLink(Link oldLink, Link newLink)
NOTE: The solution may look a bit complicated, but this is prepared for Special, extended links.
public boolean removeLink(Link link)
NOTE: The Link is always disconnected before removing from the neurons using Link.disconnect() .
Also please note that there is no removeLink(int index) method, because the link needs to be looked up anyway, to disconnect it.
Link.disconnect()public void setInput(double[] values)
public void setInput(java.util.List<java.lang.Double> values)
public double[] getOutput(double[] outputs)
outputs - Array to put the outputs into.
If too small or null, we allocate a new double array for the values.public void randomize()
public void innervate()
This method works as follows:
maxCycles times, if topology is recurrent.
public java.lang.String toString()
toString in class java.lang.Objectpublic void setTrainer(Trainer trainer)
trainer - the trainerpublic Trainer getTrainer()
public int getMaxCycles()
public void setMaxCycles(int maxCycles)
maxCycles - the maximum number of cycles (iterations) per turn.public void setZeroInputAfterFirstCycle(boolean makeZero)
Default: false, i.e. do not reset to zero.
public boolean getZeroInputAfterFirstCycle()
public static NeuralNet load(java.io.File file, IOFilter filter) throws java.io.IOException
file - file to load the network fromfilter - the filterjava.io.IOExceptionpublic void save(java.io.File file)
throws java.io.IOException
java.io.IOExceptionpublic void fromXML(org.jdom2.Element element)
public org.jdom2.Element toXML(org.jdom2.Element element)
public NeuralNet clone()
clone in class java.lang.ObjectCloneException - if cloning fails internally.public void linkNet(NeuralNet other)
Links: just propagating neuron output over link without changing it.
other - the net that will be linked