Class MapUtils


  • public class MapUtils
    extends java.lang.Object
    Utilities for network maps.
    Since:
    3.3
    • Constructor Detail

      • MapUtils

        private MapUtils()
        Class contains only static methods.
    • 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 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,
                                                                      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 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.
      • 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 - if data 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 - if data is empty.