CentroidMedianEliminator implements OutlierEliminator<T> { @Override public Set<T> removeOutliers(Set<T> candidates) { final PointList<T> candidateList = new PointList<T>(pointFactory, candidates); if (candidateList.size() <= 2) { return candidates; } final T centroid = candidateList.getMedianPoint(); final double medianCentroidDistance = candidateList.calculateMedianReferencePointDistance(centroid); final double thresholdDistance = medianThresholdFactor * medianCentroidDistance; final Iterator<T> it = candidates.iterator(); while (it.hasNext()) { final NicGeoPoint point = it.next(); if (point.calculateDistanceTo(centroid) > thresholdDistance) { it.remove(); } } return candidates; } CentroidMedianEliminator(PointFactory factory, final double medianThresholdFactor); @Override Set<T> removeOutliers(Set<T> candidates);  }
@Test public void testThatNoPointIsEliminatedWhenTheTotalAmountOfPointsIsToSmall() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesTooSmallAmount(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesTooSmallAmountExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThatTheOutlierIsRemovedWhenItIsObviousThatItIsAnOutlierWithVaryingGeoPoints() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesWithAnObviousOutlier(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesWithAnObviousOutlierExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThatTheOutlierIsRemovedWhenItIsObviousThatItIsAnOutlierWithTheOutlierAddedInTheMiddleOfTheMap() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesWithAnObviousOutlierInTheMiddleOfTheMap(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesWithAnObviousOutlierInTheMiddleOfTheMapExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThatGeoPointsPlacedInASquareHaveNoOutliers() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesPlacedInASquare(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesPlacedInASquareExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThatFourGeoPointsPlacedInASquareAndOnePlacedInTheMiddleHaveNoOutliers() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesPlacedInASquareAndOnePlacedInTheMiddle(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesPlacedInASquareAndOnePlacedInTheMiddleExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThatAnOutlierFarAwayFromGeoPointsPlacedInASquareIsDetectedProperly() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesPlacedInASquareAndOnePlacedFarAway(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesPlacedInASquareAndOnePlacedFarAwayExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testRasterCoordinates() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesRasterCoordinates(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesRasterCoordinatesExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void test() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesTest(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesTestExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThat2PointsFarAwayFromAnother2PointsHaveNoOutliers() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesTwoPointsFarAwayFromAnotherTwoPoints(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesTwoPointsFarAwayFromAnotherTwoPointsExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThat2PointsFarAwayFrom3PointsNearToEachAreDetectedAsOutliers() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesTwoPointsFarAwayFromThreePointsNearToEachOther(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesTwoPointsFarAwayFromThreePointsNearToEachOtherExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }
@Test public void testThatOutliersFromARealMapAreDetected() throws NicTrackerException { final Set<NicGeoPoint> geoPointsIn = CandidateFixtures.createCandidatesOutliersFromARealMap(); final Set<NicGeoPoint> expected = CandidateFixtures.createCandidatesOutliersFromARealMapExpected(); final Set<NicGeoPoint> geoPointsOut = cme.removeOutliers(geoPointsIn); assertEquals(expected, geoPointsOut); }