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

public Class MapUtils

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, .Collections, .HashMap, .List, .Comparator, org.apache.commons.math3.exception.NoDataException, org.apache.commons.math3.ml.distance.DistanceMeasure, org.apache.commons.math3.ml.neuralnet.twod.NeuronSquareMesh2D, org.apache.commons.math3.util.Pair

Utilities for network maps.
Since
3.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
MapUtils.PairNeuronDouble

Helper data structure holding a (Neuron, double) pair.

Constructor Summary

AccessConstructor and Description
private
MapUtils()

Class contains only static methods.

Method Summary

Modifier and TypeMethod and Description
public static int[][]

Returns:

the number of hits for each neuron in the map.
computeHitHistogram
(Iterable<double[]>
Feature vectors.
data
,
NeuronSquareMesh2D
Network.
map
,
DistanceMeasure
Function to use for determining the best matching unit.
distance
)

Computes the "hit" histogram of a two-dimensional map.

public static double

Returns:

the error.
computeQuantizationError
(Iterable<double[]>
Feature vectors.
data
,
Iterable<Neuron>
List of neurons to scan.
neurons
,
DistanceMeasure
Distance function.
distance
)

Computes the quantization error.

public static double

Returns:

the error.
computeTopographicError
(Iterable<double[]>
Feature vectors.
data
,
Network
Network.
net
,
DistanceMeasure
Distance function.
distance
)

Computes the topographic error.

public static double[][]

Returns:

the matrix of average distances.
computeU
(NeuronSquareMesh2D
Network.
map
,
DistanceMeasure
Function to use for computing the average distance from a neuron to its neighbours.
distance
)

Computes the U-matrix of a two-dimensional map.

public static Neuron

Returns:

the neuron whose features are closest to the given data.
findBest
(double[]
Data.
features
,
Iterable<Neuron>
List of neurons to scan. If the list is empty null will be returned.
neurons
,
DistanceMeasure
Distance function. The neuron's features are passed as the first argument to DistanceMeasure#compute(double[], double[]).
distance
)

Finds the neuron that best matches the given features.

public static Pair<Neuron, Neuron>

Returns:

the two neurons whose features are closest to the given data.
findBestAndSecondBest
(double[]
Data.
features
,
Iterable<Neuron>
List of neurons to scan. If the list is empty null will be returned.
neurons
,
DistanceMeasure
Distance function. The neuron's features are passed as the first argument to DistanceMeasure#compute(double[], double[]).
distance
)

Finds the two neurons that best match the given features.

public static Neuron[]

Returns:

the neurons, sorted in increasing order of distance in data space.
sort
(double[]
Data.
features
,
Iterable<Neuron>
List of neurons to scan. If it is empty, an empty array will be returned.
neurons
,
DistanceMeasure
Distance function.
distance
)

Creates a list of neurons sorted in increased order of the distance to the given features.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

MapUtilsback to summary
private MapUtils()

Class contains only static methods.

Method Detail

computeHitHistogramback to summary
public static int[][] computeHitHistogram(Iterable<double[]> data, NeuronSquareMesh2D map, DistanceMeasure distance)

Computes the "hit" histogram of a two-dimensional map.

Parameters
data:Iterable<double[]>

Feature vectors.

map:NeuronSquareMesh2D

Network.

distance:DistanceMeasure

Function to use for determining the best matching unit.

Returns:int[][]

the number of hits for each neuron in the map.

computeQuantizationErrorback to summary
public static double computeQuantizationError(Iterable<double[]> data, Iterable<Neuron> neurons, DistanceMeasure distance)

Computes the quantization error. The quantization error is the average distance between a feature vector and its "best matching unit" (closest neuron).

Parameters
data:Iterable<double[]>

Feature vectors.

neurons:Iterable<Neuron>

List of neurons to scan.

distance:DistanceMeasure

Distance function.

Returns:double

the error.

Exceptions
NoDataException:
if data is empty.
computeTopographicErrorback to summary
public static double computeTopographicError(Iterable<double[]> data, Network net, DistanceMeasure distance)

Computes the topographic error. The topographic error is the proportion of data for which first and second best matching units are not adjacent in the map.

Parameters
data:Iterable<double[]>

Feature vectors.

net:Network

Network.

distance:DistanceMeasure

Distance function.

Returns:double

the error.

Exceptions
NoDataException:
if data is empty.
computeUback to summary
public static double[][] computeU(NeuronSquareMesh2D map, DistanceMeasure distance)

Computes the U-matrix of a two-dimensional map.

Parameters
map:NeuronSquareMesh2D

Network.

distance:DistanceMeasure

Function to use for computing the average distance from a neuron to its neighbours.

Returns:double[][]

the matrix of average distances.

findBestback to summary
public static Neuron findBest(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance)

Finds the neuron that best matches the given features.

Parameters
features:double[]

Data.

neurons:Iterable<Neuron>

List of neurons to scan. If the list is empty null will be returned.

distance:DistanceMeasure

Distance function. The neuron's features are passed as the first argument to DistanceMeasure#compute(double[], double[]).

Returns:Neuron

the neuron whose features are closest to the given data.

Exceptions
DimensionMismatchException:
if the size of the input is not compatible with the neurons features size.
findBestAndSecondBestback to summary
public static Pair<Neuron, Neuron> findBestAndSecondBest(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance)

Finds the two neurons that best match the given features.

Parameters
features:double[]

Data.

neurons:Iterable<Neuron>

List of neurons to scan. If the list is empty null will be returned.

distance:DistanceMeasure

Distance function. The neuron's features are passed as the first argument to DistanceMeasure#compute(double[], double[]).

Returns:Pair<Neuron, Neuron>

the two neurons whose features are closest to the given data.

Exceptions
DimensionMismatchException:
if the size of the input is not compatible with the neurons features size.
sortback to summary
public static Neuron[] sort(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance)

Creates a list of neurons sorted in increased order of the distance to the given features.

Parameters
features:double[]

Data.

neurons:Iterable<Neuron>

List of neurons to scan. If it is empty, an empty array will be returned.

distance:DistanceMeasure

Distance function.

Returns:Neuron[]

the neurons, sorted in increasing order of distance in data space.

Exceptions
DimensionMismatchException:
if the size of the input is not compatible with the neurons features size.
Since
3.6
See Also
findBest(double[], Iterable, DistanceMeasure), findBestAndSecondBest(double[], Iterable, DistanceMeasure)
org.apache.commons.math3.ml.neuralnet back to summary

private Class MapUtils.PairNeuronDouble

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.ml.neuralnet.MapUtils.PairNeuronDouble

Helper data structure holding a (Neuron, double) pair.

Field Summary

Modifier and TypeField and Description
pack-priv static final Comparator<MapUtils.PairNeuronDouble>
COMPARATOR

Comparator.

private final Neuron
neuron

Key.

private final double
value

Value.

Constructor Summary

AccessConstructor and Description
pack-priv
PairNeuronDouble(Neuron
Neuron.
neuron
,
double
Value.
value
)

Method Summary

Modifier and TypeMethod and Description
public Neuron

Returns:

the neuron.
getNeuron
()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

COMPARATORback to summary
pack-priv static final Comparator<MapUtils.PairNeuronDouble> COMPARATOR

Comparator.

neuronback to summary
private final Neuron neuron

Key.

valueback to summary
private final double value

Value.

Constructor Detail

PairNeuronDoubleback to summary
pack-priv PairNeuronDouble(Neuron neuron, double value)
Parameters
neuron:Neuron

Neuron.

value:double

Value.

Method Detail

getNeuronback to summary
public Neuron getNeuron()
Returns:Neuron

the neuron.