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

public Class NeuronSquareMesh2D

extends Object
implements Iterable<Neuron>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Iterable
Imports
java.util.List, .ArrayList, .Iterator, java.io.Serializable, .ObjectInputStream, org.apache.commons.math3.ml.neuralnet.Neuron, .Network, .FeatureInitializer, .SquareNeighbourhood, org.apache.commons.math3.exception.NumberIsTooSmallException, .OutOfRangeException, .MathInternalError

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
NeuronSquareMesh2D.HorizontalDirection

Horizontal (along row) direction.

private static class
public static enum
NeuronSquareMesh2D.VerticalDirection

Vertical (along column) direction.

Field Summary

Modifier and TypeField and Description
private final long[][]
identifiers

Mapping of the 2D coordinates (in the rectangular mesh) to the neuron identifiers (attributed by the network instance).

private final SquareNeighbourhood
neighbourhood

Neighbourhood type.

private final Network
network

Underlying network.

private final int
numberOfColumns

Number of columns.

private final int
numberOfRows

Number of rows.

private static final long
serialVersionUID

Serial version ID

private final boolean
private final boolean
wrapRows

Wrap.

Constructor Summary

AccessConstructor and Description
pack-priv
NeuronSquareMesh2D(boolean
Whether to wrap the first dimension (i.e the first and last neurons will be linked together).
wrapRowDim
,
boolean
Whether to wrap the second dimension (i.e the first and last neurons will be linked together).
wrapColDim
,
SquareNeighbourhood
Neighbourhood type.
neighbourhoodType
,
double[][][]
Arrays that will initialize the features sets of the network's neurons.
featuresList
)

Constructor with restricted access, solely used for deserialization.

public
NeuronSquareMesh2D(int
Number of neurons in the first dimension.
numRows
,
boolean
Whether to wrap the first dimension (i.e the first and last neurons will be linked together).
wrapRowDim
,
int
Number of neurons in the second dimension.
numCols
,
boolean
Whether to wrap the second dimension (i.e the first and last neurons will be linked together).
wrapColDim
,
SquareNeighbourhood
Neighbourhood type.
neighbourhoodType
,
FeatureInitializer[]
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.
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.

private
NeuronSquareMesh2D(boolean
Whether to wrap the first dimension (i.e the first and last neurons will be linked together).
wrapRowDim
,
boolean
Whether to wrap the second dimension (i.e the first and last neurons will be linked together).
wrapColDim
,
SquareNeighbourhood
Neighbourhood type.
neighbourhoodType
,
Network
Underlying network.
net
,
long[][]
Neuron identifiers.
idGrid
)

Constructor with restricted access, solely used for making a deep copy.

Method Summary

Modifier and TypeMethod and Description
public synchronized NeuronSquareMesh2D

Returns:

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

Performs a deep copy of this instance.

private int[]

Returns:

an array of length 2 containing the indices of the requested location, or null if that location is not part of the map.
getLocation
(int
Row index.
row
,
int
Column index.
col
,
NeuronSquareMesh2D.HorizontalDirection
Direction along the given row (i.e. an offset will be added to the given column index.
alongRowDir
,
NeuronSquareMesh2D.VerticalDirection
Direction along the given col (i.e. an offset will be added to the given row index.
alongColDir
)

Computes the location of a neighbouring neuron.

public Network

Returns:

the network.
getNetwork
()

Retrieves the underlying network.

public Neuron

Returns:

the neuron at (i, j).
getNeuron
(int
Row index.
i
,
int
Column index.
j
)

Retrieves the neuron at location (i, j) in the map.

public Neuron

Returns:

the neuron at the requested location, or null if the location is not on the map.
getNeuron
(int
Row index.
row
,
int
Column index.
col
,
NeuronSquareMesh2D.HorizontalDirection
Direction along the given row (i.e. an offset will be added to the given column index.
alongRowDir
,
NeuronSquareMesh2D.VerticalDirection
Direction along the given col (i.e. an offset will be added to the given row index.
alongColDir
)

Retrieves the neuron at (location[0], location[1]) in the map.

public int

Returns:

the number of column.
getNumberOfColumns
()

Gets the number of neurons in each column of this map.

public int

Returns:

the number of rows.
getNumberOfRows
()

Gets the number of neurons in each row of this map.

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

identifiersback to summary
private final long[][] identifiers

Mapping of the 2D coordinates (in the rectangular mesh) to the neuron identifiers (attributed by the network instance).

neighbourhoodback to summary
private final SquareNeighbourhood neighbourhood

Neighbourhood type.

networkback to summary
private final Network network

Underlying network.

numberOfColumnsback to summary
private final int numberOfColumns

Number of columns.

numberOfRowsback to summary
private final int numberOfRows

Number of rows.

serialVersionUIDback to summary
private static final long serialVersionUID

Serial version ID

wrapColumnsback to summary
private final boolean wrapColumns

Wrap.

wrapRowsback to summary
private final boolean wrapRows

Wrap.

Constructor Detail

NeuronSquareMesh2Dback to summary
pack-priv NeuronSquareMesh2D(boolean wrapRowDim, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, double[][][] featuresList)

Constructor with restricted access, solely used for deserialization.

Parameters
wrapRowDim:boolean

Whether to wrap the first dimension (i.e the first and last neurons will be linked together).

wrapColDim:boolean

Whether to wrap the second dimension (i.e the first and last neurons will be linked together).

neighbourhoodType:SquareNeighbourhood

Neighbourhood type.

featuresList:double[][][]

Arrays that will initialize the features sets of the network's neurons.

Exceptions
NumberIsTooSmallException:
if numRows < 2 or numCols < 2.
NeuronSquareMesh2Dback to summary
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:int

Number of neurons in the first dimension.

wrapRowDim:boolean

Whether to wrap the first dimension (i.e the first and last neurons will be linked together).

numCols:int

Number of neurons in the second dimension.

wrapColDim:boolean

Whether to wrap the second dimension (i.e the first and last neurons will be linked together).

neighbourhoodType:SquareNeighbourhood

Neighbourhood type.

featureInit:FeatureInitializer[]

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.

Exceptions
NumberIsTooSmallException:
if numRows < 2 or numCols < 2.
NeuronSquareMesh2Dback to summary
private NeuronSquareMesh2D(boolean wrapRowDim, boolean wrapColDim, SquareNeighbourhood neighbourhoodType, Network net, long[][] idGrid)

Constructor with restricted access, solely used for making a deep copy.

Parameters
wrapRowDim:boolean

Whether to wrap the first dimension (i.e the first and last neurons will be linked together).

wrapColDim:boolean

Whether to wrap the second dimension (i.e the first and last neurons will be linked together).

neighbourhoodType:SquareNeighbourhood

Neighbourhood type.

net:Network

Underlying network.

idGrid:long[][]

Neuron identifiers.

Method Detail

copyback to summary
public synchronized 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:NeuronSquareMesh2D

a new instance with the same state as this instance.

Since
3.6
getLocationback to summary
private int[] getLocation(int row, int col, NeuronSquareMesh2D.HorizontalDirection alongRowDir, NeuronSquareMesh2D.VerticalDirection alongColDir)

Computes the location of a neighbouring neuron. It will return null if the resulting location is not part of the map. Position (0, 0) is at the upper-left corner of the map.

Parameters
row:int

Row index.

col:int

Column index.

alongRowDir:NeuronSquareMesh2D.HorizontalDirection

Direction along the given row (i.e. an offset will be added to the given column index.

alongColDir:NeuronSquareMesh2D.VerticalDirection

Direction along the given col (i.e. an offset will be added to the given row index.

Returns:int[]

an array of length 2 containing the indices of the requested location, or null if that location is not part of the map.

See Also
getNeuron(int, int)
getNetworkback to summary
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 the Network topology may cause this class to become inconsistent.

Returns:Network

the network.

getNeuronback to summary
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:int

Row index.

j:int

Column index.

Returns:Neuron

the neuron at (i, j).

Exceptions
OutOfRangeException:
if i or j is out of range.
See Also
getNeuron(int, int, HorizontalDirection, VerticalDirection)
getNeuronback to summary
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:int

Row index.

col:int

Column index.

alongRowDir:NeuronSquareMesh2D.HorizontalDirection

Direction along the given row (i.e. an offset will be added to the given column index.

alongColDir:NeuronSquareMesh2D.VerticalDirection

Direction along the given col (i.e. an offset will be added to the given row index.

Returns:Neuron

the neuron at the requested location, or null if the location is not on the map.

See Also
getNeuron(int, int)
getNumberOfColumnsback to summary
public int getNumberOfColumns()

Gets the number of neurons in each column of this map.

Returns:int

the number of column.

getNumberOfRowsback to summary
public int getNumberOfRows()

Gets the number of neurons in each row of this map.

Returns:int

the number of rows.

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.

Since
3.6
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.twod back to summary

public final Enum NeuronSquareMesh2D.HorizontalDirection

extends Enum<NeuronSquareMesh2D.HorizontalDirection>
Class Inheritance

Horizontal (along row) direction.
Since
3.6

Field Summary

Modifier and TypeField and Description
public static final NeuronSquareMesh2D.HorizontalDirection
CENTER

Current column.

public static final NeuronSquareMesh2D.HorizontalDirection
LEFT

Column at the left of the current column.

public static final NeuronSquareMesh2D.HorizontalDirection
RIGHT

Column at the right of the current column.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NeuronSquareMesh2D.HorizontalDirection
public static NeuronSquareMesh2D.HorizontalDirection[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CENTERback to summary
public static final NeuronSquareMesh2D.HorizontalDirection CENTER

Current column.

LEFTback to summary
public static final NeuronSquareMesh2D.HorizontalDirection LEFT

Column at the left of the current column.

RIGHTback to summary
public static final NeuronSquareMesh2D.HorizontalDirection RIGHT

Column at the right of the current column.

Constructor Detail

HorizontalDirectionback to summary
private HorizontalDirection()

Method Detail

valueOfback to summary
public static NeuronSquareMesh2D.HorizontalDirection valueOf(String name)
valuesback to summary
public static NeuronSquareMesh2D.HorizontalDirection[] values()
org.apache.commons.math3.ml.neuralnet.twod back to summary

private Class NeuronSquareMesh2D.SerializationProxy

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

Serialization.

Field Summary

Modifier and TypeField and Description
private final double[][][]
featuresList

Neurons' features.

private final SquareNeighbourhood
neighbourhood

Neighbourhood type.

private static final long
serialVersionUID

Serializable.

private final boolean
private final boolean
wrapRows

Wrap.

Constructor Summary

AccessConstructor and Description
pack-priv
SerializationProxy(boolean
Whether the row dimension is wrapped.
wrapRows
,
boolean
Whether the column dimension is wrapped.
wrapColumns
,
SquareNeighbourhood
Neighbourhood type.
neighbourhood
,
double[][][]
List of neurons features. neuronList.
featuresList
)

Method Summary

Modifier and TypeMethod and Description
private Object

Returns:

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

Custom serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

featuresListback to summary
private final double[][][] featuresList

Neurons' features.

neighbourhoodback to summary
private final SquareNeighbourhood neighbourhood

Neighbourhood type.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable.

wrapColumnsback to summary
private final boolean wrapColumns

Wrap.

wrapRowsback to summary
private final boolean wrapRows

Wrap.

Constructor Detail

SerializationProxyback to summary
pack-priv SerializationProxy(boolean wrapRows, boolean wrapColumns, SquareNeighbourhood neighbourhood, double[][][] featuresList)
Parameters
wrapRows:boolean

Whether the row dimension is wrapped.

wrapColumns:boolean

Whether the column dimension is wrapped.

neighbourhood:SquareNeighbourhood

Neighbourhood type.

featuresList:double[][][]

List of neurons features. neuronList.

Method Detail

readResolveback to summary
private Object readResolve()

Custom serialization.

Returns:Object

the Neuron for which this instance is the proxy.

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

public final Enum NeuronSquareMesh2D.VerticalDirection

extends Enum<NeuronSquareMesh2D.VerticalDirection>
Class Inheritance

Vertical (along column) direction.
Since
3.6

Field Summary

Modifier and TypeField and Description
public static final NeuronSquareMesh2D.VerticalDirection
CENTER

Current row.

public static final NeuronSquareMesh2D.VerticalDirection
DOWN

Row below the current row.

public static final NeuronSquareMesh2D.VerticalDirection
UP

Row above the current row.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static NeuronSquareMesh2D.VerticalDirection
public static NeuronSquareMesh2D.VerticalDirection[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CENTERback to summary
public static final NeuronSquareMesh2D.VerticalDirection CENTER

Current row.

DOWNback to summary
public static final NeuronSquareMesh2D.VerticalDirection DOWN

Row below the current row.

UPback to summary
public static final NeuronSquareMesh2D.VerticalDirection UP

Row above the current row.

Constructor Detail

VerticalDirectionback to summary
private VerticalDirection()

Method Detail

valueOfback to summary
public static NeuronSquareMesh2D.VerticalDirection valueOf(String name)
valuesback to summary
public static NeuronSquareMesh2D.VerticalDirection[] values()