Class NeuronSquareMesh2D
- java.lang.Object
-
- org.apache.commons.math3.ml.neuralnet.twod.NeuronSquareMesh2D
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<Neuron>
public class NeuronSquareMesh2D extends java.lang.Object implements java.lang.Iterable<Neuron>, java.io.Serializable
Neural network with the topology of a two-dimensional surface. Each neuron defines one surface element.
This network is primarily intended to represent a Self Organizing Feature Map.- Since:
- 3.3
- See Also:
org.apache.commons.math3.ml.neuralnet.sofm, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNeuronSquareMesh2D.HorizontalDirectionHorizontal (along row) direction.private static classNeuronSquareMesh2D.SerializationProxySerialization.static classNeuronSquareMesh2D.VerticalDirectionVertical (along column) direction.
-
Field Summary
Fields Modifier and Type Field Description private long[][]identifiersMapping of the 2D coordinates (in the rectangular mesh) to the neuron identifiers (attributed by thenetworkinstance).private SquareNeighbourhoodneighbourhoodNeighbourhood type.private NetworknetworkUnderlying network.private intnumberOfColumnsNumber of columns.private intnumberOfRowsNumber of rows.private static longserialVersionUIDSerial version IDprivate booleanwrapColumnsWrap.private booleanwrapRowsWrap.
-
Constructor Summary
Constructors Modifier Constructor Description (package private)NeuronSquareMesh2D(boolean wrapRowDim, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, double[][][] featuresList)Constructor with restricted access, solely used for deserialization.privateNeuronSquareMesh2D(boolean wrapRowDim, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, Network net, long[][] idGrid)Constructor with restricted access, solely used for making adeep copy.NeuronSquareMesh2D(int numRows, boolean wrapRowDim, int numCols, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, FeatureInitializer[] featureInit)Creates a two-dimensional network composed of square cells: Each neuron not located on the border of the mesh has four neurons linked to it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NeuronSquareMesh2Dcopy()Performs a deep copy of this instance.private voidcreateLinks()Creates the neighbour relationships between neurons.private int[]getLocation(int row, int col, NeuronSquareMesh2D.HorizontalDirection alongRowDir, NeuronSquareMesh2D.VerticalDirection alongColDir)Computes the location of a neighbouring neuron.NetworkgetNetwork()Retrieves the underlying network.NeurongetNeuron(int i, int j)Retrieves the neuron at location(i, j)in the map.NeurongetNeuron(int row, int col, NeuronSquareMesh2D.HorizontalDirection alongRowDir, NeuronSquareMesh2D.VerticalDirection alongColDir)Retrieves the neuron at(location[0], location[1])in the map.intgetNumberOfColumns()Gets the number of neurons in each column of this map.intgetNumberOfRows()Gets the number of neurons in each row of this map.java.util.Iterator<Neuron>iterator()private voidreadObject(java.io.ObjectInputStream in)Prevents proxy bypass.private java.lang.ObjectwriteReplace()Custom serialization.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serial version ID- See Also:
- Constant Field Values
-
network
private final Network network
Underlying network.
-
numberOfRows
private final int numberOfRows
Number of rows.
-
numberOfColumns
private final int numberOfColumns
Number of columns.
-
wrapRows
private final boolean wrapRows
Wrap.
-
wrapColumns
private final boolean wrapColumns
Wrap.
-
neighbourhood
private final SquareNeighbourhood neighbourhood
Neighbourhood type.
-
identifiers
private final long[][] identifiers
Mapping of the 2D coordinates (in the rectangular mesh) to the neuron identifiers (attributed by thenetworkinstance).
-
-
Constructor Detail
-
NeuronSquareMesh2D
NeuronSquareMesh2D(boolean wrapRowDim, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, double[][][] featuresList)Constructor with restricted access, solely used for deserialization.- Parameters:
wrapRowDim- Whether to wrap the first dimension (i.e the first and last neurons will be linked together).wrapColDim- Whether to wrap the second dimension (i.e the first and last neurons will be linked together).neighbourhoodType- Neighbourhood type.featuresList- Arrays that will initialize the features sets of the network's neurons.- Throws:
NumberIsTooSmallException- ifnumRows < 2ornumCols < 2.
-
NeuronSquareMesh2D
public NeuronSquareMesh2D(int numRows, boolean wrapRowDim, int numCols, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, FeatureInitializer[] featureInit)Creates a two-dimensional network composed of square cells: Each neuron not located on the border of the mesh has four neurons linked to it.
The links are bi-directional.
The topology of the network can also be a cylinder (if one of the dimensions is wrapped) or a torus (if both dimensions are wrapped).- Parameters:
numRows- Number of neurons in the first dimension.wrapRowDim- Whether to wrap the first dimension (i.e the first and last neurons will be linked together).numCols- Number of neurons in the second dimension.wrapColDim- Whether to wrap the second dimension (i.e the first and last neurons will be linked together).neighbourhoodType- Neighbourhood type.featureInit- Array of functions that will initialize the corresponding element of the features set of each newly created neuron. In particular, the size of this array defines the size of feature set.- Throws:
NumberIsTooSmallException- ifnumRows < 2ornumCols < 2.
-
NeuronSquareMesh2D
private NeuronSquareMesh2D(boolean wrapRowDim, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, Network net, long[][] idGrid)Constructor with restricted access, solely used for making adeep copy.- Parameters:
wrapRowDim- Whether to wrap the first dimension (i.e the first and last neurons will be linked together).wrapColDim- Whether to wrap the second dimension (i.e the first and last neurons will be linked together).neighbourhoodType- Neighbourhood type.net- Underlying network.idGrid- Neuron identifiers.
-
-
Method Detail
-
copy
public NeuronSquareMesh2D 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
-
iterator
public java.util.Iterator<Neuron> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Neuron>- Since:
- 3.6
-
getNetwork
public Network getNetwork()
Retrieves the underlying network. A reference is returned (enabling, for example, the network to be trained). This also implies that calling methods that modify theNetworktopology may cause this class to become inconsistent.- Returns:
- the network.
-
getNumberOfRows
public int getNumberOfRows()
Gets the number of neurons in each row of this map.- Returns:
- the number of rows.
-
getNumberOfColumns
public int getNumberOfColumns()
Gets the number of neurons in each column of this map.- Returns:
- the number of column.
-
getNeuron
public Neuron getNeuron(int i, int j)
Retrieves the neuron at location(i, j)in the map. The neuron at position(0, 0)is located at the upper-left corner of the map.- Parameters:
i- Row index.j- Column index.- Returns:
- the neuron at
(i, j). - Throws:
OutOfRangeException- ifiorjis out of range.- See Also:
getNeuron(int,int,HorizontalDirection,VerticalDirection)
-
getNeuron
public Neuron getNeuron(int row, int col, NeuronSquareMesh2D.HorizontalDirection alongRowDir, NeuronSquareMesh2D.VerticalDirection alongColDir)
Retrieves the neuron at(location[0], location[1])in the map. The neuron at position(0, 0)is located at the upper-left corner of the map.- Parameters:
row- Row index.col- Column index.alongRowDir- Direction along the givenrow(i.e. an offset will be added to the given column index.alongColDir- Direction along the givencol(i.e. an offset will be added to the given row index.- Returns:
- the neuron at the requested location, or
nullif the location is not on the map. - See Also:
getNeuron(int,int)
-
getLocation
private int[] getLocation(int row, int col, NeuronSquareMesh2D.HorizontalDirection alongRowDir, NeuronSquareMesh2D.VerticalDirection alongColDir)Computes the location of a neighbouring neuron. It will returnnullif the resulting location is not part of the map. Position(0, 0)is at the upper-left corner of the map.- Parameters:
row- Row index.col- Column index.alongRowDir- Direction along the givenrow(i.e. an offset will be added to the given column index.alongColDir- Direction along the givencol(i.e. an offset will be added to the given row index.- Returns:
- an array of length 2 containing the indices of the requested
location, or
nullif that location is not part of the map. - See Also:
getNeuron(int,int)
-
createLinks
private void createLinks()
Creates the neighbour relationships between neurons.
-
readObject
private void readObject(java.io.ObjectInputStream in)
Prevents proxy bypass.- Parameters:
in- Input stream.
-
writeReplace
private java.lang.Object writeReplace()
Custom serialization.- Returns:
- the proxy instance that will be actually serialized.
-
-