From ed4817c7301a942ac17d9a015a90ad8e406dc0e5 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Fri, 26 Jun 2020 18:29:37 +0200 Subject: [PATCH] MATH-1548: Remove methods redundant with functionality defined in "NeuronSquareMesh2D". --- .../commons/math4/ml/neuralnet/MapUtils.java | 85 ------------------- 1 file changed, 85 deletions(-) diff --git a/src/main/java/org/apache/commons/math4/ml/neuralnet/MapUtils.java b/src/main/java/org/apache/commons/math4/ml/neuralnet/MapUtils.java index 40500b654..b6065bdcd 100644 --- a/src/main/java/org/apache/commons/math4/ml/neuralnet/MapUtils.java +++ b/src/main/java/org/apache/commons/math4/ml/neuralnet/MapUtils.java @@ -17,13 +17,9 @@ package org.apache.commons.math4.ml.neuralnet; -import java.util.Collection; -import java.util.HashMap; import java.util.List; - import org.apache.commons.math4.exception.NoDataException; import org.apache.commons.math4.ml.distance.DistanceMeasure; -import org.apache.commons.math4.ml.neuralnet.twod.NeuronSquareMesh2D; /** * Utilities for network maps. @@ -36,87 +32,6 @@ public class MapUtils { */ private MapUtils() {} - /** - * Computes the - * U-matrix of a two-dimensional map. - * - * @param map Network. - * @param distance Function to use for computing the average - * distance from a neuron to its neighbours. - * @return the matrix of average distances. - */ - public static double[][] computeU(NeuronSquareMesh2D map, - DistanceMeasure distance) { - final int numRows = map.getNumberOfRows(); - final int numCols = map.getNumberOfColumns(); - final double[][] uMatrix = new double[numRows][numCols]; - - final Network net = map.getNetwork(); - - for (int i = 0; i < numRows; i++) { - for (int j = 0; j < numCols; j++) { - final Neuron neuron = map.getNeuron(i, j); - final Collection neighbours = net.getNeighbours(neuron); - final double[] features = neuron.getFeatures(); - - double d = 0; - int count = 0; - for (Neuron n : neighbours) { - ++count; - d += distance.compute(features, n.getFeatures()); - } - - uMatrix[i][j] = d / count; - } - } - - return uMatrix; - } - - /** - * Computes the "hit" histogram of a two-dimensional map. - * - * @param data Feature vectors. - * @param map Network. - * @param distance Function to use for determining the best matching unit. - * @return the number of hits for each neuron in the map. - */ - public static int[][] computeHitHistogram(Iterable data, - NeuronSquareMesh2D map, - DistanceMeasure distance) { - final HashMap hit = new HashMap<>(); - final MapRanking rank = new MapRanking(map.getNetwork(), distance); - - for (double[] f : data) { - final Neuron best = rank.rank(f, 1).get(0); - final Integer count = hit.get(best); - if (count == null) { - hit.put(best, 1); - } else { - hit.put(best, count + 1); - } - } - - // Copy the histogram data into a 2D map. - final int numRows = map.getNumberOfRows(); - final int numCols = map.getNumberOfColumns(); - final int[][] histo = new int[numRows][numCols]; - - for (int i = 0; i < numRows; i++) { - for (int j = 0; j < numCols; j++) { - final Neuron neuron = map.getNeuron(i, j); - final Integer count = hit.get(neuron); - if (count == null) { - histo[i][j] = 0; - } else { - histo[i][j] = count; - } - } - } - - return histo; - } - /** * Computes the quantization error. * The quantization error is the average distance between a feature vector