/**
* @return a comparator for sorting the optima.
*/
private Comparator<PointVectorValuePair> getPairComparator() {
return new Comparator<PointVectorValuePair>() {
private final RealVector target = new ArrayRealVector(optimizer.getTarget(), false);
private final RealMatrix weight = optimizer.getWeight();
public int compare(final PointVectorValuePair o1,
final PointVectorValuePair o2) {
if (o1 == null) {
return (o2 == null) ? 0 : 1;
} else if (o2 == null) {
return -1;
}
return Double.compare(weightedResidual(o1),
weightedResidual(o2));
}
private double weightedResidual(final PointVectorValuePair pv) {
final RealVector v = new ArrayRealVector(pv.getValueRef(), false);
final RealVector r = target.subtract(v);
return r.dotProduct(weight.operate(r));
}
};
}