Class Network

  • All Implemented Interfaces:
    Iterable<Neuron>

    public class Network
    extends Object
    implements Iterable<Neuron>
    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
    • Constructor Detail

      • Network

        public Network​(long firstId,
                       int featureSize)
        Parameters:
        firstId - Identifier of the first neuron that will be added to this network.
        featureSize - Size of the neuron's features.
    • Method Detail

      • from

        public static Network from​(int featureSize,
                                   long[] idList,
                                   double[][] featureList,
                                   long[][] neighbourIdList)
        Builds a network from a list of neurons and their neighbours.
        Parameters:
        featureSize - Number of features.
        idList - List of neuron identifiers.
        featureList - List of neuron features.
        neighbourIdList - Links associated to each of the neurons in idList.
        Returns:
        a new instance.
        Throws:
        IllegalArgumentException - if an inconsistency is detected.
      • copy

        public 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:
        a new instance with the same state as this instance.
        Since:
        3.6
      • createNeuron

        public long createNeuron​(double[] features)
        Creates a neuron and assigns it a unique identifier.
        Parameters:
        features - Initial values for the neuron's features.
        Returns:
        the neuron's identifier.
        Throws:
        IllegalArgumentException - if the length of features is different from the expected size (as set by the constructor).
      • deleteNeuron

        public void deleteNeuron​(Neuron neuron)
        Deletes a neuron. Links from all neighbours to the removed neuron will also be deleted.
        Parameters:
        neuron - Neuron to be removed from this network.
        Throws:
        NoSuchElementException - if n does not belong to this network.
      • getFeaturesSize

        public int getFeaturesSize()
        Gets the size of the neurons' features set.
        Returns:
        the size of the features set.
      • addLink

        public void addLink​(Neuron a,
                            Neuron b)
        Adds a link from neuron 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.
        Parameters:
        a - Neuron.
        b - Neuron.
        Throws:
        NoSuchElementException - if the neurons do not exist in the network.
      • getNeuron

        public Neuron getNeuron​(long id)
        Retrieves the neuron with the given (unique) id.
        Parameters:
        id - Identifier.
        Returns:
        the neuron associated with the given id.
        Throws:
        NoSuchElementException - if the neuron does not exist in the network.
      • getNeighbours

        public Collection<NeurongetNeighbours​(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 - Neurons for which to retrieve the neighbours.
        exclude - Neurons to exclude from the returned list. Can be null.
        Returns:
        the list of neighbours.
      • getNeighbours

        public Collection<NeurongetNeighbours​(Neuron neuron,
                                                Iterable<Neuron> exclude)
        Retrieves the neighbours of the given neuron.
        Parameters:
        neuron - Neuron for which to retrieve the neighbours.
        exclude - Neurons to exclude from the returned list. Can be null.
        Returns:
        the list of neighbours.