Class LeastMedianOfSquares<Model,Point>
java.lang.Object
org.ddogleg.fitting.modelset.lmeds.LeastMedianOfSquares<Model,Point>
- All Implemented Interfaces:
InlierFraction
,ModelMatcher<Model,
,Point> ModelMatcherPost<Model,
Point>
- Direct Known Subclasses:
LeastMedianOfSquares_MT
public class LeastMedianOfSquares<Model,Point>
extends Object
implements ModelMatcherPost<Model,Point>, InlierFraction
Another technique similar to RANSAC known as Least Median of Squares (LMedS). For each iteration a small number N points are selected. A model is fit to these points and then the error is computed for the whole set. The model which minimizes the median is selected as the final model. No pruning or formal selection of inlier set is done.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected double
protected double
protected LeastMedianOfSquares<Model,
Point>.@Nullable TrialHelper protected Ransac.InitializeModels<Model,
Point> Optional function for initializing generator and distance functionsprotected final double
protected int[]
protected final double
protected final ModelManager<Model>
protected int
protected final int
number of times it performs its fit cycle -
Constructor Summary
ConstructorDescriptionLeastMedianOfSquares
(long randSeed, int totalCycles, double maxMedianError, double inlierFraction, ModelManager<Model> modelManager, Class<Point> pointType) Configures the algorithm.LeastMedianOfSquares
(long randSeed, int totalCycles, ModelManager<Model> modelManager, Class<Point> pointType) Configures the algorithm. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
If the maximum number of iterations has changed then re-generate the RNG for each trialprotected void
computeInlierSet
(List<Point> dataSet, int n, LeastMedianOfSquares<Model, Point>.TrialHelper helper) double
Gets the inlier set's fractional valuedouble
Value of the best median error.int
getInputIndex
(int matchIndex) For an item in the match set, return the index of the item in the original input set.If configured to computer the inlier set it returns the computed inliers.int
This is the minimum number of observations which can be input and produce a valid model.Model for the match setReturns a class for the input point objectReturns a class for the input point objectboolean
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.void
reset()
Resets the model matcher to its original state.void
setErrorFraction
(double errorFraction) Specifies the inlier set as a fractionvoid
setModel
(Factory<ModelGenerator<Model, Point>> factoryGenerator, Factory<DistanceFromModel<Model, Point>> factoryDistance) Specifies the internal model.void
setSampleSize
(int sampleSize) Number of points it samples to compute a model from.
-
Field Details
-
trialRNG
-
totalCycles
protected final int totalCyclesnumber of times it performs its fit cycle -
sampleSize
protected int sampleSize -
maxMedianError
protected final double maxMedianError -
ModelManager
-
matchToInput
protected int[] matchToInput -
bestMedian
protected volatile double bestMedian -
errorFraction
protected double errorFraction -
inlierSet
-
inlierFrac
protected final double inlierFrac -
helper
-
initializeModels
Optional function for initializing generator and distance functions
-
-
Constructor Details
-
LeastMedianOfSquares
public LeastMedianOfSquares(long randSeed, int totalCycles, double maxMedianError, double inlierFraction, ModelManager<Model> modelManager, Class<Point> pointType) Configures the algorithm.- Parameters:
randSeed
- Random seed used internally.totalCycles
- Number of random draws it will make when estimating model parameters.maxMedianError
- If the best median error is larger than this it is considered a failure.inlierFraction
- Data which is this fraction or lower is considered an inlier and used to recompute model parameters at the end. Set to 0 to turn off. Domain: 0 to 1.
-
LeastMedianOfSquares
public LeastMedianOfSquares(long randSeed, int totalCycles, ModelManager<Model> modelManager, Class<Point> pointType) Configures the algorithm.- Parameters:
randSeed
- Random seed used internally.totalCycles
- Number of random draws it will make when estimating model parameters.
-
-
Method Details
-
setModel
public void setModel(Factory<ModelGenerator<Model, Point>> factoryGenerator, Factory<DistanceFromModel<Model, Point>> factoryDistance) Description copied from interface:ModelMatcherPost
Specifies the internal model. Factories are provided since each thread might need its own unique instance of the generator and distance function if they are not thread safe.- Specified by:
setModel
in interfaceModelMatcherPost<Model,
Point> - Parameters:
factoryGenerator
-ModelGenerator
factoryDistance
-DistanceFromModel
-
setSampleSize
public void setSampleSize(int sampleSize) Number of points it samples to compute a model from. Typically this is the minimum number of points needed.- Parameters:
sampleSize
- Number of points sampled when computing the model.
-
process
Description copied from interface:ModelMatcher
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.- Specified by:
process
in 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.
-
computeInlierSet
protected void computeInlierSet(List<Point> dataSet, int n, LeastMedianOfSquares<Model, Point>.TrialHelper helper) -
checkTrialGenerators
protected void checkTrialGenerators()If the maximum number of iterations has changed then re-generate the RNG for each trial -
getErrorFraction
public double getErrorFraction()Description copied from interface:InlierFraction
Gets the inlier set's fractional value- Specified by:
getErrorFraction
in interfaceInlierFraction
-
setErrorFraction
public void setErrorFraction(double errorFraction) Description copied from interface:InlierFraction
Specifies the inlier set as a fraction- Specified by:
setErrorFraction
in interfaceInlierFraction
- Parameters:
errorFraction
- inlier threshold. Must be from 0 to 1, inclusive.
-
getModelParameters
Description copied from interface:ModelMatcher
Model for the match set- Specified by:
getModelParameters
in interfaceModelMatcher<Model,
Point> - Returns:
- model.
-
getMatchSet
If configured to computer the inlier set it returns the computed inliers. Otherwise it returns the data set orginally passed in.- Specified by:
getMatchSet
in interfaceModelMatcher<Model,
Point> - Returns:
- Set of points that are inliers to the returned model parameters..
-
getInputIndex
public int getInputIndex(int matchIndex) Description copied from interface:ModelMatcher
For an item in the match set, return the index of the item in the original input set.- Specified by:
getInputIndex
in interfaceModelMatcher<Model,
Point> - Parameters:
matchIndex
- Index of an element in the match set.- Returns:
- Index of the same element in the original input list.
-
getFitQuality
public double getFitQuality()Value of the best median error.- Specified by:
getFitQuality
in interfaceModelMatcher<Model,
Point> - Returns:
- Quality of fit to matched set of points
-
getMinimumSize
public int getMinimumSize()Description copied from interface:ModelMatcher
This is the minimum number of observations which can be input and produce a valid model.- Specified by:
getMinimumSize
in interfaceModelMatcher<Model,
Point> - Returns:
- Minimum number of sample points
-
reset
public void reset()Description copied from interface:ModelMatcher
Resets the model matcher to its original state. This means that given identical inputs it would produce the same outputs- Specified by:
reset
in interfaceModelMatcher<Model,
Point>
-
getPointType
Description copied from interface:ModelMatcher
Returns a class for the input point object- Specified by:
getPointType
in interfaceModelMatcher<Model,
Point>
-
getModelType
Description copied from interface:ModelMatcher
Returns a class for the input point object- Specified by:
getModelType
in interfaceModelMatcher<Model,
Point>
-