Top Description Inners Fields Constructors Methods
org.apache.commons.math3.ml.neuralnet

public Class Network

extends Object
implements Iterable<Neuron>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Iterable
Imports
java.io.Serializable, .ObjectInputStream, java.util.NoSuchElementException, .List, .ArrayList, .Set, .HashSet, .Collection, .Iterator, .Comparator, .Collections, .Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicLong, org.apache.commons.math3.exception.DimensionMismatchException, .MathIllegalStateException

Neural network, composed of 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.
Since
3.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Network.NeuronIdentifierComparator

Comparator that prescribes an order of the neurons according to the increasing order of their identifier.

private static class

Field Summary

Modifier and TypeField and Description
private final int
featureSize

Neuron's features set size.

private final ConcurrentHashMap<Long, Set<Long>>
linkMap

Links.

private final ConcurrentHashMap<Long, Neuron>
neuronMap

Neurons.

private final AtomicLong
nextId

Next available neuron identifier.

private static final long
serialVersionUID

Serializable.

Constructor Summary

AccessConstructor and Description
pack-priv
Network(long
Next available identifier.
nextId
,
int
Number of features.
featureSize
,
Neuron[]
Neurons.
neuronList
,
long[][]
Links associated to each of the neurons in neuronList.
neighbourIdList
)

Constructor with restricted access, solely used for deserialization.

public
Network(long
Identifier for the first neuron that will be added to this network.
initialIdentifier
,
int
Size of the neuron's features.
featureSize
)

Method Summary

Modifier and TypeMethod and Description
private void
addLinkToLinkSet(Set<Long>
Neuron identifier.
linkSet
,
long
Neuron identifier.
id
)

Adds a link to neuron id in given linkSet.

public synchronized Network

Returns:

a new instance with the same state as this instance.
copy
()

Performs a deep copy of this instance.

public long

Returns:

the neuron's identifier.
createNeuron
(double[]
Initial values for the neuron's features.
features
)

Creates a neuron and assigns it a unique identifier.

private Long

Returns:

a value that will serve as a unique identifier.
createNextId
()

Creates a neuron identifier.

private void
deleteLinkFromLinkSet(Set<Long>
Neuron identifier.
linkSet
,
long
Neuron identifier.
id
)

Deletes a link to neuron id in given linkSet.

public void
deleteNeuron(Neuron
Neuron to be removed from this network.
neuron
)

Deletes a neuron.

public int

Returns:

the size of the features set.
getFeaturesSize
()

Gets the size of the neurons' features set.

public Collection<Neuron>

Returns:

the list of neighbours.
getNeighbours
(Iterable<Neuron>
Neurons for which to retrieve the neighbours.
neurons
)

Retrieves the neurons in the neighbourhood of any neuron in the neurons list.

public Collection<Neuron>

Returns:

the list of neighbours.
getNeighbours
(Iterable<Neuron>
Neurons for which to retrieve the neighbours.
neurons
,
Iterable<Neuron>
Neurons to exclude from the returned list. Can be null.
exclude
)

Retrieves the neurons in the neighbourhood of any neuron in the neurons list.

public Collection<Neuron>

Returns:

the list of neighbours.
getNeighbours
(Neuron
Neuron for which to retrieve the neighbours.
neuron
)

Retrieves the neighbours of the given neuron.

public Collection<Neuron>

Returns:

the list of neighbours.
getNeighbours
(Neuron
Neuron for which to retrieve the neighbours.
neuron
,
Iterable<Neuron>
Neurons to exclude from the returned list. Can be null.
exclude
)

Retrieves the neighbours of the given neuron.

public Neuron

Returns:

the neuron associated with the given id.
getNeuron
(long
Identifier.
id
)

Retrieves the neuron with the given (unique) id.

public Collection<Neuron>

Returns:

a list of neurons, sorted in the order prescribed by the given comparator.
getNeurons
(Comparator<Neuron>
Comparator used for sorting the neurons.
comparator
)

Creates a list of the neurons, sorted in a custom order.

public Iterator<Neuron>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

private void
readObject(ObjectInputStream
Input stream.
in
)

Prevents proxy bypass.

private Object

Returns:

the proxy instance that will be actually serialized.
writeReplace
()

Custom serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

featureSizeback to summary
private final int featureSize

Neuron's features set size.

linkMapback to summary
private final ConcurrentHashMap<Long, Set<Long>> linkMap

Links.

neuronMapback to summary
private final ConcurrentHashMap<Long, Neuron> neuronMap

Neurons.

nextIdback to summary
private final AtomicLong nextId

Next available neuron identifier.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable.

Constructor Detail

Networkback to summary
pack-priv Network(long nextId, int featureSize, Neuron[] neuronList, long[][] neighbourIdList)

Constructor with restricted access, solely used for deserialization.

Parameters
nextId:long

Next available identifier.

featureSize:int

Number of features.

neuronList:Neuron[]

Neurons.

neighbourIdList:long[][]

Links associated to each of the neurons in neuronList.

Exceptions
MathIllegalStateException:
if an inconsistency is detected (which probably means that the serialized form has been corrupted).
Networkback to summary
public Network(long initialIdentifier, int featureSize)
Parameters
initialIdentifier:long

Identifier for the first neuron that will be added to this network.

featureSize:int

Size of the neuron's features.

Method Detail

addLinkToLinkSetback to summary
private void addLinkToLinkSet(Set<Long> linkSet, long id)

Adds a link to neuron id in given linkSet.

Note

no check verifies that the identifier indeed belongs to this network.

Parameters
linkSet:Set<Long>

Neuron identifier.

id:long

Neuron identifier.

copyback to summary
public synchronized Network copy()

Performs a deep copy of this instance. Upon return, the copied and original instances will be independent: Updating one will not affect the other.

Returns:Network

a new instance with the same state as this instance.

Since
3.6
createNeuronback to summary
public long createNeuron(double[] features)

Creates a neuron and assigns it a unique identifier.

Parameters
features:double[]

Initial values for the neuron's features.

Returns:long

the neuron's identifier.

Exceptions
DimensionMismatchException:
if the length of features is different from the expected size (as set by the constructor).
createNextIdback to summary
private Long createNextId()

Creates a neuron identifier.

Returns:Long

a value that will serve as a unique identifier.

deleteLinkFromLinkSetback to summary
private void deleteLinkFromLinkSet(Set<Long> linkSet, long id)

Deletes a link to neuron id in given linkSet.

Note

no check verifies that the identifier indeed belongs to this network.

Parameters
linkSet:Set<Long>

Neuron identifier.

id:long

Neuron identifier.

deleteNeuronback to summary
public void deleteNeuron(Neuron neuron)

Deletes a neuron. Links from all neighbours to the removed neuron will also be deleted.

Parameters
neuron:Neuron

Neuron to be removed from this network.

Exceptions
NoSuchElementException:
if n does not belong to this network.
getFeaturesSizeback to summary
public int getFeaturesSize()

Gets the size of the neurons' features set.

Returns:int

the size of the features set.

getNeighboursback to summary
public Collection<Neuron> getNeighbours(Iterable<Neuron> neurons)

Retrieves the neurons in the neighbourhood of any neuron in the neurons list.

Parameters
neurons:Iterable<Neuron>

Neurons for which to retrieve the neighbours.

Returns:Collection<Neuron>

the list of neighbours.

See Also
getNeighbours(Iterable, Iterable)
getNeighboursback to summary
public Collection<Neuron> getNeighbours(Iterable<Neuron> neurons, Iterable<Neuron> exclude)

Retrieves the neurons in the neighbourhood of any neuron in the neurons list. The exclude list allows to retrieve the "concentric" neighbourhoods by removing the neurons that belong to the inner "circles".

Parameters
neurons:Iterable<Neuron>

Neurons for which to retrieve the neighbours.

exclude:Iterable<Neuron>

Neurons to exclude from the returned list. Can be null.

Returns:Collection<Neuron>

the list of neighbours.

getNeighboursback to summary
public Collection<Neuron> getNeighbours(Neuron neuron)

Retrieves the neighbours of the given neuron.

Parameters
neuron:Neuron

Neuron for which to retrieve the neighbours.

Returns:Collection<Neuron>

the list of neighbours.

See Also
getNeighbours(Neuron, Iterable)
getNeighboursback to summary
public Collection<Neuron> getNeighbours(Neuron neuron, Iterable<Neuron> exclude)

Retrieves the neighbours of the given neuron.

Parameters
neuron:Neuron

Neuron for which to retrieve the neighbours.

exclude:Iterable<Neuron>

Neurons to exclude from the returned list. Can be null.

Returns:Collection<Neuron>

the list of neighbours.

getNeuronback to summary
public Neuron getNeuron(long id)

Retrieves the neuron with the given (unique) id.

Parameters
id:long

Identifier.

Returns:Neuron

the neuron associated with the given id.

Exceptions
NoSuchElementException:
if the neuron does not exist in the network.
getNeuronsback to summary
public Collection<Neuron> getNeurons(Comparator<Neuron> comparator)

Creates a list of the neurons, sorted in a custom order.

Parameters
comparator:Comparator<Neuron>

Comparator used for sorting the neurons.

Returns:Collection<Neuron>

a list of neurons, sorted in the order prescribed by the given comparator.

See Also
NeuronIdentifierComparator
iteratorback to summary
public Iterator<Neuron> iterator()

Implements java.lang.Iterable.iterator.

Doc from java.lang.Iterable.iterator.

Returns an iterator over elements of type T.

Returns:Iterator<Neuron>

an Iterator.

readObjectback to summary
private void readObject(ObjectInputStream in)

Prevents proxy bypass.

Parameters
in:ObjectInputStream

Input stream.

writeReplaceback to summary
private Object writeReplace()

Custom serialization.

Returns:Object

the proxy instance that will be actually serialized.

org.apache.commons.math3.ml.neuralnet back to summary

public Class Network.NeuronIdentifierComparator

extends Object
implements Comparator<Neuron>, Serializable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.ml.neuralnet.Network.NeuronIdentifierComparator
All Implemented Interfaces
java.io.Serializable, java.util.Comparator

Comparator that prescribes an order of the neurons according to the increasing order of their identifier.

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Version identifier.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
compare(Neuron
the first object to be compared.
a
,
Neuron
the second object to be compared.
b
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Version identifier.

Constructor Detail

NeuronIdentifierComparatorback to summary
public NeuronIdentifierComparator()

Method Detail

compareback to summary
public int compare(Neuron a, Neuron b)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
a:Neuron

the first object to be compared.

b:Neuron

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

org.apache.commons.math3.ml.neuralnet back to summary

private Class Network.SerializationProxy

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.ml.neuralnet.Network.SerializationProxy
All Implemented Interfaces
java.io.Serializable

Serialization.

Field Summary

Modifier and TypeField and Description
private final int
featureSize

Number of features.

private final long[][]
private final Neuron[]
neuronList

Neurons.

private final long
nextId

Next identifier.

private static final long
serialVersionUID

Serializable.

Constructor Summary

AccessConstructor and Description
pack-priv
SerializationProxy(long
Next available identifier.
nextId
,
int
Number of features.
featureSize
,
Neuron[]
Neurons.
neuronList
,
long[][]
Links associated to each of the neurons in neuronList.
neighbourIdList
)

Method Summary

Modifier and TypeMethod and Description
private Object

Returns:

the Network for which this instance is the proxy.
readResolve
()

Custom serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

featureSizeback to summary
private final int featureSize

Number of features.

neighbourIdListback to summary
private final long[][] neighbourIdList

Links.

neuronListback to summary
private final Neuron[] neuronList

Neurons.

nextIdback to summary
private final long nextId

Next identifier.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable.

Constructor Detail

SerializationProxyback to summary
pack-priv SerializationProxy(long nextId, int featureSize, Neuron[] neuronList, long[][] neighbourIdList)
Parameters
nextId:long

Next available identifier.

featureSize:int

Number of features.

neuronList:Neuron[]

Neurons.

neighbourIdList:long[][]

Links associated to each of the neurons in neuronList.

Method Detail

readResolveback to summary
private Object readResolve()

Custom serialization.

Returns:Object

the Network for which this instance is the proxy.