You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2020/06/28 22:57:47 UTC
[commons-math] 06/08: MATH-1548: Remove methods redundant with
functionality defined in "NeuronSquareMesh2D".
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit ed4817c7301a942ac17d9a015a90ad8e406dc0e5
Author: Gilles Sadowski <gi...@gmail.com>
AuthorDate: Fri Jun 26 18:29:37 2020 +0200
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 40500b6..b6065bd 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.
@@ -37,87 +33,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
* and its "best matching unit" (closest neuron).