org.ddogleg.fitting.modelset.ransac
Class Ransac<Model,Point>
- java.lang.Object
-
- org.ddogleg.fitting.modelset.ransac.Ransac<Model,Point>
-
- All Implemented Interfaces:
- ModelMatcher<Model,Point>
public class Ransac<Model,Point> extends java.lang.Object implements ModelMatcher<Model,Point>
RANSAC is an abbreviation for "RANdom SAmple Consensus" and is an iterative algorithm. The model with the largest set of inliers is found by randomly sampling the set of points and fitting a model. The algorithm terminates when the maximum number of iterations has been reached. An inlier is defined as a point which has an error less than a user specified threshold to the estimated model being considered. The algorithm was first published by Fischler and Bolles in 1981."
Sample Points: By default the minimum number of points are sampled. The user to override this default and set it to any number.
-
-
Constructor Summary
Constructors Constructor and Description Ransac(long randSeed, ModelManager<Model> modelManager, ModelGenerator<Model,Point> modelGenerator, DistanceFromModel<Model,Point> modelDistance, int maxIterations, double thresholdFit)Creates a new instance of the ransac algorithm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublegetFitQuality()Returns the metric used to evaluate the quality of fit.intgetInputIndex(int matchIndex)For an item in the match set, return the index of the item in the original input set.java.util.List<Point>getMatchSet()A set of points which match the provided parameters.intgetMaxIterations()intgetMinimumSize()This is the minimum number of observations which can be input and produce a valid model.ModelgetModelParameters()Model for the match setdoublegetThresholdFit()voidinitialize(java.util.List<Point> dataSet)Initialize internal data structuresbooleanprocess(java.util.List<Point> dataSet)Finds a set of points from the provided list that are a good fit for the internal model and computes the fit parameters for the model.static <T> voidrandomDraw(java.util.List<T> dataSet, int numSample, java.util.List<T> initialSample, java.util.Random rand)Two different methods are used to select the initial set of points depending on if the data set is much larger or smaller than the initial sample sizevoidsetMaxIterations(int maxIterations)voidsetSampleSize(int sampleSize)Override the number of points that are sampled and used to generate models.voidsetThresholdFit(double thresholdFit)
-
-
-
Constructor Detail
-
Ransac
public Ransac(long randSeed, ModelManager<Model> modelManager, ModelGenerator<Model,Point> modelGenerator, DistanceFromModel<Model,Point> modelDistance, int maxIterations, double thresholdFit)Creates a new instance of the ransac algorithm. The number of points sampled will default to the minimum number. To override this default invokesetSampleSize(int).- Parameters:
randSeed- The random seed used by the random number generator.modelGenerator- Creates new model(s) given a small number of points.modelDistance- Computes the difference between a point an a model.maxIterations- The maximum number of iterations the RANSAC algorithm will perform.thresholdFit- How close of a fit a points needs to be to the model to be considered a fit.
-
-
Method Detail
-
process
public boolean process(java.util.List<Point> dataSet)
Description copied from interface:ModelMatcherFinds a set of points from the provided list that are a good fit for the internal model and computes the fit parameters for the model.- Specified by:
processin interfaceModelMatcher<Model,Point>- Parameters:
dataSet- Set of points (with noise) that are to be fit.- Returns:
- true if it successfully found a solution or false if not.
-
initialize
public void initialize(java.util.List<Point> dataSet)
Initialize internal data structures
-
randomDraw
public static <T> void randomDraw(java.util.List<T> dataSet, int numSample, java.util.List<T> initialSample, java.util.Random rand)Two different methods are used to select the initial set of points depending on if the data set is much larger or smaller than the initial sample size
-
getMatchSet
public java.util.List<Point> getMatchSet()
Description copied from interface:ModelMatcherA set of points which match the provided parameters.- Specified by:
getMatchSetin interfaceModelMatcher<Model,Point>- Returns:
- List of points in the match set.
-
getInputIndex
public int getInputIndex(int matchIndex)
Description copied from interface:ModelMatcherFor an item in the match set, return the index of the item in the original input set.- Specified by:
getInputIndexin interfaceModelMatcher<Model,Point>- Parameters:
matchIndex- Index of an element in the match set.- Returns:
- Index of the same element in the original input list.
-
getModelParameters
public Model getModelParameters()
Description copied from interface:ModelMatcherModel for the match set- Specified by:
getModelParametersin interfaceModelMatcher<Model,Point>- Returns:
- model.
-
getFitQuality
public double getFitQuality()
Description copied from interface:ModelMatcherReturns the metric used to evaluate the quality of fit. Meaning is implementation specific. Larger or smaller values could be preferred depending on implementation..- Specified by:
getFitQualityin interfaceModelMatcher<Model,Point>- Returns:
- Quality of fit to matched set of points
-
getMaxIterations
public int getMaxIterations()
-
setMaxIterations
public void setMaxIterations(int maxIterations)
-
getMinimumSize
public int getMinimumSize()
Description copied from interface:ModelMatcherThis is the minimum number of observations which can be input and produce a valid model.- Specified by:
getMinimumSizein interfaceModelMatcher<Model,Point>- Returns:
- Minimum number of sample points
-
setSampleSize
public void setSampleSize(int sampleSize)
Override the number of points that are sampled and used to generate models. If this value is not set it defaults to the minimum number.- Parameters:
sampleSize- Number of sample points.
-
getThresholdFit
public double getThresholdFit()
-
setThresholdFit
public void setThresholdFit(double thresholdFit)
-
-
DataMelt 3.0 © DataMelt by jWork.ORG