Package org.apache.commons.math3.ml.neuralnet

# Class MapUtils

java.lang.Object
org.apache.commons.math3.ml.neuralnet.MapUtils

public class MapUtils extends Object
Utilities for network maps.

Since:
  3.3

## Method Summary

Modifier and Type
Method
Description
`static int[][]`
`computeHitHistogram(Iterable<double[]> data, NeuronSquareMesh2D map, DistanceMeasure distance)`
Computes the "hit" histogram of a two-dimensional map.
`static double`
`computeQuantizationError(Iterable<double[]> data, Iterable<Neuron> neurons, DistanceMeasure distance)`
Computes the quantization error.
`static double`
`computeTopographicError(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, Iterable<Neuron> neurons, DistanceMeasure distance)`
Finds the neuron that best matches the given features.
`static Pair<Neuron,Neuron>`
`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 given `features`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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 empty `null` will be returned.
  `distance` - Distance function. The neuron's features are passed as the first argument to `DistanceMeasure.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 empty `null` will be returned.
  `distance` - Distance function. The neuron's features are passed as the first argument to `DistanceMeasure.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, Iterable<Neuron> neurons, DistanceMeasure distance)
Creates a list of neurons sorted in increased order of the distance to the given `features`.

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(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` - if `data` is 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` - if `data` is empty.