/** * Make sure the function getInputIndex() returns the original index */ @Test public void checkMatchSetToInputIndex() { double mean = 2.5; double tol = 0.2; // generate the points with a smaller tolerance to account for fitting error // later on. ModelMatcher<double[],Double> alg = createModel(4, tol * 0.95); List<Double> samples = createSampleSet(100, mean, tol, 0.1); assertTrue(alg.process(samples)); List<Double> matchSet = alg.getMatchSet(); // sanity check to make sure there is a large enough match set assertTrue(matchSet.size() > 20); int orderNotTheSame = 0; for( int i = 0; i < matchSet.size(); i++ ) { int expected = samples.indexOf(matchSet.get(i)); int found = alg.getInputIndex(i); if( found != i ) orderNotTheSame++; assertEquals(expected, found); } // sanity check to make sure the order has been changed assertTrue(orderNotTheSame != matchSet.size()); }
private ModelMatcher<double[],Double> createModel(int minPoints, double fitThreshold) { DoubleArrayManager manager = new DoubleArrayManager(1); DistanceFromMeanModel dist = new DistanceFromMeanModel(); MeanModelFitter fitter = new MeanModelFitter(); return createModelMatcher(manager,dist, fitter,fitter, minPoints, fitThreshold); }
/** * Sees if it can correctly select a model set and determine the best fit parameters for * a simple test case. */ @Test public void performSimpleModelFit() { double mean = 2.5; double tol = 0.2; // generate the points with a smaller tolerance to account for fitting error // later on. ModelMatcher<double[],Double> alg = createModel(4, tol * 0.95); List<Double> samples = createSampleSet(100, mean, tol, 0.1); assertTrue(alg.process(samples)); List<Double> matchSet = alg.getMatchSet(); if (checkInlierSet) assertTrue(matchSet.size() / 90.0 >= minMatchFrac); assertEquals(inlierMean, alg.getModelParameters()[0], parameterTol); }
/** * Multiple data sets are processed in an attempt to see if it is properly reinitializing * itself and returns the correct solutions. */ @Test public void runMultipleTimes() { double mean = 2.5; double tol = 0.2; // generate the points with a smaller tolerance to account for fitting error // later on. ModelMatcher<double[],Double> alg = createModel(4, tol); for (int i = 0; i < 10; i++) { // try different sample sizes in each trial. a bug was found once where // a small value of N than previous caused a problem int N = 200 - i * 10; List<Double> samples = createSampleSet(N, mean, tol * 0.90, 0.1); assertTrue(alg.process(samples)); List<Double> matchSet = alg.getMatchSet(); double foundMean = alg.getModelParameters()[0]; if (checkInlierSet) assertTrue(matchSet.size() / (N * 0.9) >= minMatchFrac); assertEquals(inlierMean, foundMean, parameterTol); } }