Package com.irurueta.numerical.robust
Class RANSACRobustEstimator<T>
java.lang.Object
com.irurueta.numerical.robust.RobustEstimator<T>
com.irurueta.numerical.robust.RANSACRobustEstimator<T>
- Type Parameters:
T- type of object to be estimated.
This class implements RANSAC (RANdom SAmple Consensus) algorithm to robustly
estimate a data model.
RANSAC is based on the idea that given a proportion of outliers (that is
estimated while the algorithm is run), it is needed a certain number of
random sub-samples to obtain required data with a certain level of confidence.
To determine whether a sample is an outlier or not, provided constant
threshold is used. If a threshold cannot be determined beforehand, then it
is better to use LMedS algorithm, at the expense of slightly less accurate
results.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classContains data related to estimated inliers. -
Field Summary
FieldsModifier and TypeFieldDescriptionData related to inliers found for best result.private TBest solution that has been found so far during an estimation.private booleanIndicates whether inliers must be computed and kept.private booleanIndicates whether residuals must be computed and kept.private doubleAmount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).static final booleanIndicates that by default inliers will only be computed but not kept.static final booleanIndicates that by default residuals will only be computed but not kept.static final doubleConstant defining default confidence of the estimated result, which is 99%.static final intDefault maximum allowed number of iterations.static final doubleMaximum allowed confidence value.private intMaximum allowed number of iterations.static final doubleMinimum allowed confidence value.static final intMinimum allowed number of iterations.static final doubleMinimum allowed threshold to determine inliers.private intNumber of iterations to be done to obtain required confidence.private SubsetSelectorInstance 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.RANSACRobustEstimator(RANSACRobustEstimatorListener<T> listener) Constructor with listener. -
Method Summary
Modifier and TypeMethodDescriptionestimate()Robustly estimates an instance of T.Gets data related to inliers found for best result.Returns best solution that has been found so far during an estimation.doubleReturns 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.intMaximum allowed number of iterations.Returns method being used for robust estimation.intReturns number of iterations to be done to obtain required confidence.booleanIndicates whether inliers must be computed and kept.booleanIndicates whether residuals must be computed and kept.booleanisReady()Indicates if estimator is ready to start the estimation process.voidsetComputeAndKeepInliersEnabled(boolean computeAndKeepInliers) Specifies whether inliers must be computed and kept.voidsetComputeAndKeepResidualsEnabled(boolean computeAndKeepResiduals) Specifies whether residuals must be computed and kept.voidsetConfidence(double confidence) Sets amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).voidsetMaxIterations(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 the 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:
-
DEFAULT_COMPUTE_AND_KEEP_INLIERS
public static final boolean DEFAULT_COMPUTE_AND_KEEP_INLIERSIndicates that by default inliers will only be computed but not kept.- See Also:
-
DEFAULT_COMPUTE_AND_KEEP_RESIDUALS
public static final boolean DEFAULT_COMPUTE_AND_KEEP_RESIDUALSIndicates that by default residuals will only be computed but not kept.- 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. -
nIters
private int nItersNumber of iterations to be done to obtain required confidence. -
bestResult
Best solution that has been found so far during an estimation. -
bestInliersData
Data related to inliers found for best result. -
computeAndKeepInliers
private boolean computeAndKeepInliersIndicates whether inliers must be computed and kept. -
computeAndKeepResiduals
private boolean computeAndKeepResidualsIndicates whether residuals must be computed and kept.
-
-
Constructor Details
-
RANSACRobustEstimator
public RANSACRobustEstimator()Constructor. -
RANSACRobustEstimator
Constructor with listener.- Parameters:
listener- listener to be notified of events such as when estimation starts, ends or its progress significantly changes, as well as in charge of picking samples and doing per-iteration estimations.
-
-
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.
-
getBestInliersData
Gets data related to inliers found for best result.- Returns:
- data related to inliers found for best result.
-
isComputeAndKeepInliersEnabled
public boolean isComputeAndKeepInliersEnabled()Indicates whether inliers must be computed and kept.- Returns:
- true if inliers must be computed and kept, false if inliers only need to be computed but not kept.
-
setComputeAndKeepInliersEnabled
Specifies whether inliers must be computed and kept.- Parameters:
computeAndKeepInliers- true if inliers must be computed and kept, false if inliers only need to be computed but not kept.- Throws:
LockedException- if estimator is locked.
-
isComputeAndKeepResidualsEnabled
public boolean isComputeAndKeepResidualsEnabled()Indicates whether residuals must be computed and kept.- Returns:
- true if residuals must be computed and kept, false if residuals only need to be computed but not kept.
-
setComputeAndKeepResidualsEnabled
public void setComputeAndKeepResidualsEnabled(boolean computeAndKeepResiduals) throws LockedException Specifies whether residuals must be computed and kept.- Parameters:
computeAndKeepResiduals- true if residuals must be computed and kept, false if residuals only need to be computed but not kept.- Throws:
LockedException- if estimator is locked.
-
isReady
public boolean isReady()Indicates if estimator is ready to start the estimation process.- Overrides:
isReadyin classRobustEstimator<T>- Returns:
- true if ready, false otherwise.
-
estimate
Robustly estimates an instance of T.- Specified by:
estimatein 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:
getInliersDatain classRobustEstimator<T>- Returns:
- data about inliers or null if estimation has not been done.
-
getMethod
Returns method being used for robust estimation.- Specified by:
getMethodin classRobustEstimator<T>- Returns:
- method being used for robust estimation.
-