public class Network extends java.lang.Object implements java.lang.Iterable<Neuron>, java.io.Serializable
Neuron
instances and the links
between them.
Although updating a neuron's state is thread-safe, modifying the
network's topology (adding or removing links) is not.Modifier and Type | Class and Description |
---|---|
static class |
Network.NeuronIdentifierComparator
Comparator that prescribes an order of the neurons according
to the increasing order of their identifier.
|
private static class |
Network.SerializationProxy
Serialization.
|
Modifier and Type | Field and Description |
---|---|
private int |
featureSize
Neuron's features set size.
|
private java.util.concurrent.ConcurrentHashMap<java.lang.Long,java.util.Set<java.lang.Long>> |
linkMap
Links.
|
private java.util.concurrent.ConcurrentHashMap<java.lang.Long,Neuron> |
neuronMap
Neurons.
|
private java.util.concurrent.atomic.AtomicLong |
nextId
Next available neuron identifier.
|
private static long |
serialVersionUID
Serializable.
|
Constructor and Description |
---|
Network(long initialIdentifier,
int featureSize) |
Network(long nextId,
int featureSize,
Neuron[] neuronList,
long[][] neighbourIdList)
Constructor with restricted access, solely used for deserialization.
|
Modifier and Type | Method and Description |
---|---|
void |
addLink(Neuron a,
Neuron b)
Adds a link from neuron
a to neuron b . |
private void |
addLinkToLinkSet(java.util.Set<java.lang.Long> linkSet,
long id)
Adds a link to neuron
id in given linkSet . |
long |
createNeuron(double[] features)
Creates a neuron and assigns it a unique identifier.
|
private java.lang.Long |
createNextId()
Creates a neuron identifier.
|
void |
deleteLink(Neuron a,
Neuron b)
Deletes the link between neurons
a and b . |
private void |
deleteLinkFromLinkSet(java.util.Set<java.lang.Long> linkSet,
long id)
Deletes a link to neuron
id in given linkSet . |
void |
deleteNeuron(Neuron neuron)
Deletes a neuron.
|
int |
getFeaturesSize()
Gets the size of the neurons' features set.
|
java.util.Collection<Neuron> |
getNeighbours(java.lang.Iterable<Neuron> neurons)
Retrieves the neurons in the neighbourhood of any neuron in the
neurons list. |
java.util.Collection<Neuron> |
getNeighbours(java.lang.Iterable<Neuron> neurons,
java.lang.Iterable<Neuron> exclude)
Retrieves the neurons in the neighbourhood of any neuron in the
neurons list. |
java.util.Collection<Neuron> |
getNeighbours(Neuron neuron)
Retrieves the neighbours of the given neuron.
|
java.util.Collection<Neuron> |
getNeighbours(Neuron neuron,
java.lang.Iterable<Neuron> exclude)
Retrieves the neighbours of the given neuron.
|
Neuron |
getNeuron(long id)
Retrieves the neuron with the given (unique)
id . |
java.util.Collection<Neuron> |
getNeurons(java.util.Comparator<Neuron> comparator)
Creates a list of the neurons, sorted in a custom order.
|
java.util.Iterator<Neuron> |
iterator() |
private void |
readObject(java.io.ObjectInputStream in)
Prevents proxy bypass.
|
private java.lang.Object |
writeReplace()
Custom serialization.
|
private static final long serialVersionUID
private final java.util.concurrent.ConcurrentHashMap<java.lang.Long,Neuron> neuronMap
private final java.util.concurrent.atomic.AtomicLong nextId
private final int featureSize
private final java.util.concurrent.ConcurrentHashMap<java.lang.Long,java.util.Set<java.lang.Long>> linkMap
Network(long nextId, int featureSize, Neuron[] neuronList, long[][] neighbourIdList)
nextId
- Next available identifier.featureSize
- Number of features.neuronList
- Neurons.neighbourIdList
- Links associated to each of the neurons in
neuronList
.MathIllegalStateException
- if an inconsistency is detected
(which probably means that the serialized form has been corrupted).public Network(long initialIdentifier, int featureSize)
initialIdentifier
- Identifier for the first neuron that
will be added to this network.featureSize
- Size of the neuron's features.public java.util.Iterator<Neuron> iterator()
iterator
in interface java.lang.Iterable<Neuron>
public java.util.Collection<Neuron> getNeurons(java.util.Comparator<Neuron> comparator)
comparator
- Comparator
used for sorting the neurons.comparator
.Network.NeuronIdentifierComparator
public long createNeuron(double[] features)
features
- Initial values for the neuron's features.DimensionMismatchException
- if the length of features
is different from the expected size (as set by the
constructor
).public void deleteNeuron(Neuron neuron)
deleted
.neuron
- Neuron to be removed from this network.java.util.NoSuchElementException
- if n
does not belong to
this network.public int getFeaturesSize()
public void addLink(Neuron a, Neuron b)
a
to neuron b
.
Note: the link is not bi-directional; if a bi-directional link is
required, an additional call must be made with a
and
b
exchanged in the argument list.a
- Neuron.b
- Neuron.java.util.NoSuchElementException
- if the neurons do not exist in the
network.private void addLinkToLinkSet(java.util.Set<java.lang.Long> linkSet, long id)
id
in given linkSet
.
Note: no check verifies that the identifier indeed belongs
to this network.linkSet
- Neuron identifier.id
- Neuron identifier.public void deleteLink(Neuron a, Neuron b)
a
and b
.a
- Neuron.b
- Neuron.java.util.NoSuchElementException
- if the neurons do not exist in the
network.private void deleteLinkFromLinkSet(java.util.Set<java.lang.Long> linkSet, long id)
id
in given linkSet
.
Note: no check verifies that the identifier indeed belongs
to this network.linkSet
- Neuron identifier.id
- Neuron identifier.public Neuron getNeuron(long id)
id
.id
- Identifier.id
.java.util.NoSuchElementException
- if the neuron does not exist in the
network.public java.util.Collection<Neuron> getNeighbours(java.lang.Iterable<Neuron> neurons)
neurons
list.neurons
- Neurons for which to retrieve the neighbours.getNeighbours(Iterable,Iterable)
public java.util.Collection<Neuron> getNeighbours(java.lang.Iterable<Neuron> neurons, java.lang.Iterable<Neuron> exclude)
neurons
list.
The exclude
list allows to retrieve the "concentric"
neighbourhoods by removing the neurons that belong to the inner
"circles".neurons
- Neurons for which to retrieve the neighbours.exclude
- Neurons to exclude from the returned list.
Can be null
.public java.util.Collection<Neuron> getNeighbours(Neuron neuron)
neuron
- Neuron for which to retrieve the neighbours.getNeighbours(Neuron,Iterable)
public java.util.Collection<Neuron> getNeighbours(Neuron neuron, java.lang.Iterable<Neuron> exclude)
neuron
- Neuron for which to retrieve the neighbours.exclude
- Neurons to exclude from the returned list.
Can be null
.private java.lang.Long createNextId()
private void readObject(java.io.ObjectInputStream in)
in
- Input stream.private java.lang.Object writeReplace()
Copyright (c) 2003-2014 Apache Software Foundation