Class MapUtils
- java.lang.Object
-
- org.apache.commons.math3.ml.neuralnet.MapUtils
-
public class MapUtils extends java.lang.Object
Utilities for network maps.- Since:
- 3.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
MapUtils.PairNeuronDouble
Helper data structure holding a (Neuron, double) pair.
-
Constructor Summary
Constructors Modifier Constructor Description private
MapUtils()
Class contains only static methods.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int[][]
computeHitHistogram(java.lang.Iterable<double[]> data, NeuronSquareMesh2D map, DistanceMeasure distance)
Computes the "hit" histogram of a two-dimensional map.static double
computeQuantizationError(java.lang.Iterable<double[]> data, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Computes the quantization error.static double
computeTopographicError(java.lang.Iterable<double[]> data, Network net, DistanceMeasure distance)
Computes the topographic error.static double[][]
computeU(NeuronSquareMesh2D map, DistanceMeasure distance)
Computes the U-matrix of a two-dimensional map.static Neuron
findBest(double[] features, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Finds the neuron that best matches the given features.static Pair<Neuron,Neuron>
findBestAndSecondBest(double[] features, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Finds the two neurons that best match the given features.static Neuron[]
sort(double[] features, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Creates a list of neurons sorted in increased order of the distance to the givenfeatures
.
-
-
-
Method Detail
-
findBest
public static Neuron findBest(double[] features, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Finds the neuron that best matches the given features.- Parameters:
features
- Data.neurons
- List of neurons to scan. If the list is emptynull
will be returned.distance
- Distance function. The neuron's features are passed as the first argument toDistanceMeasure.compute(double[],double[])
.- Returns:
- the neuron whose features are closest to the given data.
- Throws:
DimensionMismatchException
- if the size of the input is not compatible with the neurons features size.
-
findBestAndSecondBest
public static Pair<Neuron,Neuron> findBestAndSecondBest(double[] features, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Finds the two neurons that best match the given features.- Parameters:
features
- Data.neurons
- List of neurons to scan. If the list is emptynull
will be returned.distance
- Distance function. The neuron's features are passed as the first argument toDistanceMeasure.compute(double[],double[])
.- Returns:
- the two neurons whose features are closest to the given data.
- Throws:
DimensionMismatchException
- if the size of the input is not compatible with the neurons features size.
-
sort
public static Neuron[] sort(double[] features, java.lang.Iterable<Neuron> neurons, DistanceMeasure distance)
Creates a list of neurons sorted in increased order of the distance to the givenfeatures
.- Parameters:
features
- Data.neurons
- List of neurons to scan. If it is empty, an empty array will be returned.distance
- Distance function.- Returns:
- the neurons, sorted in increasing order of distance in data space.
- Throws:
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)
-
computeU
public static double[][] computeU(NeuronSquareMesh2D map, DistanceMeasure distance)
Computes the U-matrix of a two-dimensional map.- Parameters:
map
- Network.distance
- Function to use for computing the average distance from a neuron to its neighbours.- Returns:
- the matrix of average distances.
-
computeHitHistogram
public static int[][] computeHitHistogram(java.lang.Iterable<double[]> data, NeuronSquareMesh2D map, DistanceMeasure distance)
Computes the "hit" histogram of a two-dimensional map.- Parameters:
data
- Feature vectors.map
- Network.distance
- Function to use for determining the best matching unit.- Returns:
- the number of hits for each neuron in the map.
-
computeQuantizationError
public static double computeQuantizationError(java.lang.Iterable<double[]> data, java.lang.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
- Feature vectors.neurons
- List of neurons to scan.distance
- Distance function.- Returns:
- the error.
- Throws:
NoDataException
- ifdata
is empty.
-
computeTopographicError
public static double computeTopographicError(java.lang.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
- Feature vectors.net
- Network.distance
- Distance function.- Returns:
- the error.
- Throws:
NoDataException
- ifdata
is empty.
-
-