Remove methods redundant with functionality defined in "NeuronSquareMesh2D".
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 <a href="http://en.wikipedia.org/wiki/U-Matrix">
- * U-matrix</a> 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<Neuron> 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<double[]> data,
- NeuronSquareMesh2D map,
- DistanceMeasure distance) {
- final HashMap<Neuron, Integer> 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
