Package com.irurueta.numerical.robust
Class MSACRobustEstimator<T>
java.lang.Object
com.irurueta.numerical.robust.RobustEstimator<T>
com.irurueta.numerical.robust.MSACRobustEstimator<T>
- Type Parameters:
T
- type of object to be estimated.
This class implements MSAC (Median SAmple Consensus) algorithm to robustly
estimate a data model.
MSAC is a mixture between LMedS and RANSAC, where a fixed threshold is
used such as in RANSAC to determine the number of remaining iterations, and
the least median of residuals is used to pick the best solution, rather than
the one producing a higher number of inliers based on the fixed threshold,
such as in RANSAC.
This algorithm requires a threshold known beforehand such as RANSAC, but
might get better accuracy if the inlier samples are very accurate, since
the solution with the smallest median of residuals will be picked. In typical
situations however, this algorithm will produce similar results to RANSAC in
both terms of accuracy and computational cost, since typically inlier samples
tend to have certain error.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Contains data related to inliers estimated in one iteration. -
Field Summary
FieldsModifier and TypeFieldDescriptionData related to solution producing the largest number of inliers.private T
Best solution that has been found so far during an estimation.Data related to inliers found for best result.private double
Amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).static final double
Constant defining default confidence of estimated result, which is 99%.static final int
Default maximum allowed number of iterations.private int
Number of iterations to be done to obtain required confidence.static final double
Maximum allowed confidence value.private int
Maximum allowed number of iterations.static final double
Minimum allowed confidence value.static final int
Minimum allowed number of iterations.static final double
Minimum allowed threshold to determine inliers.private SubsetSelector
Instance in charge of picking random subsets of samples.Fields inherited from class com.irurueta.numerical.robust.RobustEstimator
DEFAULT_PROGRESS_DELTA, listener, locked, MAX_PROGRESS_DELTA, MIN_PROGRESS_DELTA, progressDelta
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.MSACRobustEstimator
(MSACRobustEstimatorListener<T> listener) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> void
computeInliers
(T iterResult, double threshold, double[] residualsTemp, LMedSRobustEstimatorListener<T> listener, com.irurueta.sorting.Sorter<Double> sorter, MSACRobustEstimator.MSACInliersData inliersData) Computes inliers data for current iteration.estimate()
Robustly estimates an instance of T.Returns data related to solution producing the largest number of inliers.Returns best solution that has been found so far during an estimation.Returns data related to the best inliers found for best result.double
Returns amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).Returns data about inliers once estimation has been done.int
Maximum allowed number of iterations.Returns method being used for robust estimation.int
Returns number of iterations to be done to obtain required confidence.boolean
isReady()
Indicates if estimator is ready to start the estimation process.void
setConfidence
(double confidence) Sets amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).void
setMaxIterations
(int maxIterations) Sets maximum allowed number of iterations.Methods inherited from class com.irurueta.numerical.robust.RobustEstimator
getListener, getProgressDelta, isListenerAvailable, isLocked, setListener, setProgressDelta
-
Field Details
-
DEFAULT_CONFIDENCE
public static final double DEFAULT_CONFIDENCEConstant defining default confidence of estimated result, which is 99%. This means that with a probability of 99% estimation will be accurate because chosen sub-samples will be inliers.- See Also:
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONSDefault maximum allowed number of iterations.- See Also:
-
MIN_CONFIDENCE
public static final double MIN_CONFIDENCEMinimum allowed confidence value.- See Also:
-
MAX_CONFIDENCE
public static final double MAX_CONFIDENCEMaximum allowed confidence value.- See Also:
-
MIN_ITERATIONS
public static final int MIN_ITERATIONSMinimum allowed number of iterations.- See Also:
-
MIN_THRESHOLD
public static final double MIN_THRESHOLDMinimum allowed threshold to determine inliers.- See Also:
-
confidence
private double confidenceAmount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0. -
maxIterations
private int maxIterationsMaximum allowed number of iterations. When the maximum number of iterations is exceeded, result will not be available, however an approximate result will be available for retrieval. -
subsetSelector
Instance in charge of picking random subsets of samples. -
iters
private int itersNumber of iterations to be done to obtain required confidence. -
bestResult
Best solution that has been found so far during an estimation. -
bestResultInliersData
Data related to inliers found for best result. -
bestNumberInliersData
Data related to solution producing the largest number of inliers.
-
-
Constructor Details
-
MSACRobustEstimator
public MSACRobustEstimator()Constructor. -
MSACRobustEstimator
Constructor.- Parameters:
listener
- listener to handle events raised by this estimator.
-
-
Method Details
-
getConfidence
public double getConfidence()Returns amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0.- Returns:
- amount of confidence as a value between 0.0 and 1.0.
-
setConfidence
Sets amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%). The amount of confidence indicates the probability that the estimated result is correct. Usually this value will be close to 1.0, but not exactly 1.0.- Parameters:
confidence
- confidence to be set as a value between 0.0 and 1.0.- Throws:
IllegalArgumentException
- if provided value is not between 0.0 and 1.0.LockedException
- if this estimator is locked because an estimation is being computed.
-
getMaxIterations
public int getMaxIterations()Maximum allowed number of iterations. When the maximum number of iterations is exceeded, result will not be available, however an approximate result will be available for retrieval.- Returns:
- maximum allowed number of iterations.
-
setMaxIterations
Sets maximum allowed number of iterations. When the maximum number of iterations is exceeded, result will not be available, however an approximate result will be available for retrieval.- Parameters:
maxIterations
- maximum allowed number of iterations to be set.- Throws:
IllegalArgumentException
- if provided value is less than 1.LockedException
- if this estimator is locked because an estimation is being computed.
-
getNIters
public int getNIters()Returns number of iterations to be done to obtain required confidence.- Returns:
- number of iterations to be done to obtain required confidence.
-
getBestResult
Returns best solution that has been found so far during an estimation.- Returns:
- best solution that has been found so far during an estimation.
-
getBestResultInliersData
Returns data related to the best inliers found for best result.- Returns:
- data related to inliers found for best result.
-
getBestNumberInliersData
Returns data related to solution producing the largest number of inliers.- Returns:
- data related to solution producing the largest number of inliers.
-
isReady
public boolean isReady()Indicates if estimator is ready to start the estimation process.- Overrides:
isReady
in classRobustEstimator<T>
- Returns:
- true if ready, false otherwise.
-
estimate
Robustly estimates an instance of T.- Specified by:
estimate
in classRobustEstimator<T>
- Returns:
- estimated object.
- Throws:
LockedException
- if robust estimator is locked.NotReadyException
- if provided input data is not enough to start the estimation.RobustEstimatorException
- if estimation fails for any reason (i.e. numerical instability, no solution available, etc).
-
getInliersData
Returns data about inliers once estimation has been done.- Specified by:
getInliersData
in classRobustEstimator<T>
- Returns:
- data about inliers or null if estimation has not been done.
-
getMethod
Returns method being used for robust estimation.- Specified by:
getMethod
in classRobustEstimator<T>
- Returns:
- method being used for robust estimation.
-
computeInliers
private static <T> void computeInliers(T iterResult, double threshold, double[] residualsTemp, LMedSRobustEstimatorListener<T> listener, com.irurueta.sorting.Sorter<Double> sorter, MSACRobustEstimator.MSACInliersData inliersData) Computes inliers data for current iteration.- Type Parameters:
T
- type of result to be estimated.- Parameters:
iterResult
- result to be tested on current iteration.threshold
- threshold to determine whether samples are inliers or not.residualsTemp
- temporal array to store residuals, since median computation requires modifying the original array.listener
- listener to obtain residuals for samples.sorter
- sorter instance to compute median of residuals.inliersData
- inliers data to be reused on each iteration
-