Class MapUtils
java.lang.Object
org.apache.commons.math3.ml.neuralnet.MapUtils
Utilities for network maps.
- Since:
- 3.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic int[][]computeHitHistogram(Iterable<double[]> data, NeuronSquareMesh2D map, DistanceMeasure distance) Computes the "hit" histogram of a two-dimensional map.static doublecomputeQuantizationError(Iterable<double[]> data, Iterable<Neuron> neurons, DistanceMeasure distance) Computes the quantization error.static doublecomputeTopographicError(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 NeuronfindBest(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance) Finds the neuron that best matches the given features.findBestAndSecondBest(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance) Finds the two neurons that best match the given features.static Neuron[]sort(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance) Creates a list of neurons sorted in increased order of the distance to the givenfeatures.
-
Method Details
-
findBest
public static Neuron findBest(double[] features, 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 emptynullwill 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, 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 emptynullwill 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
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:
-
computeU
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(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(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- Feature vectors.neurons- List of neurons to scan.distance- Distance function.- Returns:
- the error.
- Throws:
NoDataException- ifdatais empty.
-
computeTopographicError
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- Feature vectors.net- Network.distance- Distance function.- Returns:
- the error.
- Throws:
NoDataException- ifdatais empty.
-