MapUtils { public static Neuron findBest(double[] features, Iterable<Neuron> neurons, DistanceMeasure distance) { Neuron best = null; double min = Double.POSITIVE_INFINITY; for (final Neuron n : neurons) { final double d = distance.compute(n.getFeatures(), features); if (d < min) { min = d; best = n; } } return best; } private  MapUtils(); static Neuron findBest(double[] features,
                                  Iterable<Neuron> neurons,
                                  DistanceMeasure distance); static Pair<Neuron, Neuron> findBestAndSecondBest(double[] features,
                                                             Iterable<Neuron> neurons,
                                                             DistanceMeasure distance); static double[][] computeU(NeuronSquareMesh2D map,
                                      DistanceMeasure distance); static int[][] computeHitHistogram(Iterable<double[]> data,
                                              NeuronSquareMesh2D map,
                                              DistanceMeasure distance); static double computeQuantizationError(Iterable<double[]> data,
                                                  Iterable<Neuron> neurons,
                                                  DistanceMeasure distance); static double computeTopographicError(Iterable<double[]> data,
                                                 Network net,
                                                 DistanceMeasure distance);  }
@Test public void testFindClosestNeuron() { final FeatureInitializer init = new OffsetFeatureInitializer(FeatureInitializerFactory.uniform(-0.1, 0.1)); final FeatureInitializer[] initArray = { init }; final Network net = new NeuronString(3, false, initArray).getNetwork(); final DistanceMeasure dist = new EuclideanDistance(); final Set<Neuron> allBest = new HashSet<Neuron>(); final Set<Neuron> best = new HashSet<Neuron>(); double[][] features; best.clear(); features = new double[][] { { -1 }, { 0.4 }, }; for (double[] f : features) { best.add(MapUtils.findBest(f, net, dist)); } Assert.assertEquals(1, best.size()); allBest.addAll(best); best.clear(); features = new double[][] { { 0.6 }, { 1.4 }, }; for (double[] f : features) { best.add(MapUtils.findBest(f, net, dist)); } Assert.assertEquals(1, best.size()); allBest.addAll(best); best.clear(); features = new double[][] { { 1.6 }, { 3 }, }; for (double[] f : features) { best.add(MapUtils.findBest(f, net, dist)); } Assert.assertEquals(1, best.size()); allBest.addAll(best); Assert.assertEquals(3, allBest.size()); }