Use a "static" instance rather than an anonymous one instantiated
on-the-fly.
This commit is contained in:
parent
4a1708d2e1
commit
fff5c35b27
|
@ -20,9 +20,9 @@ package org.apache.commons.math3.ml.neuralnet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.apache.commons.math3.exception.NoDataException;
|
import org.apache.commons.math3.exception.NoDataException;
|
||||||
import org.apache.commons.math3.ml.distance.DistanceMeasure;
|
import org.apache.commons.math3.ml.distance.DistanceMeasure;
|
||||||
|
@ -137,13 +137,7 @@ public class MapUtils {
|
||||||
list.add(new PairNeuronDouble(n, d));
|
list.add(new PairNeuronDouble(n, d));
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(list, new Comparator<PairNeuronDouble>() {
|
Collections.sort(list, PairNeuronDouble.COMPARATOR);
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
|
||||||
public int compare(final PairNeuronDouble pn1, final PairNeuronDouble pn2) {
|
|
||||||
return Double.compare(pn1.getValue(), pn2.getValue());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
final int len = list.size();
|
final int len = list.size();
|
||||||
final Neuron[] sorted = new Neuron[len];
|
final Neuron[] sorted = new Neuron[len];
|
||||||
|
@ -300,9 +294,19 @@ public class MapUtils {
|
||||||
* Helper data structure holding a (Neuron, double) pair.
|
* Helper data structure holding a (Neuron, double) pair.
|
||||||
*/
|
*/
|
||||||
private static class PairNeuronDouble {
|
private static class PairNeuronDouble {
|
||||||
/** Key */
|
/** Comparator. */
|
||||||
|
static final Comparator<PairNeuronDouble> COMPARATOR
|
||||||
|
= new Comparator<PairNeuronDouble>() {
|
||||||
|
/** {@inheritDoc} */
|
||||||
|
@Override
|
||||||
|
public int compare(PairNeuronDouble o1,
|
||||||
|
PairNeuronDouble o2) {
|
||||||
|
return Double.compare(o1.value, o2.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** Key. */
|
||||||
private final Neuron neuron;
|
private final Neuron neuron;
|
||||||
/** Value */
|
/** Value. */
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,11 +323,5 @@ public class MapUtils {
|
||||||
return neuron;
|
return neuron;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the value. */
|
|
||||||
public double getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue