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 class
Contains data related to estimated inliers. -
Field Summary
FieldsModifier and TypeFieldDescriptionData related to inliers found for best result.private T
Best solution that has been found so far during an estimation.private boolean
Indicates whether inliers must be computed and kept.private boolean
Indicates whether residuals must be computed and kept.private double
Amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).static final boolean
Indicates that by default inliers will only be computed but not kept.static final boolean
Indicates that by default residuals will only be computed but not kept.static final double
Constant defining default confidence of the estimated result, which is 99%.static final int
Default maximum allowed number of iterations.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 int
Number of iterations to be done to obtain required confidence.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.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.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
Indicates whether inliers must be computed and kept.boolean
Indicates whether residuals must be computed and kept.boolean
isReady()
Indicates if estimator is ready to start the estimation process.void
setComputeAndKeepInliersEnabled
(boolean computeAndKeepInliers) Specifies whether inliers must be computed and kept.void
setComputeAndKeepResidualsEnabled
(boolean computeAndKeepResiduals) Specifies whether residuals must be computed and kept.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 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:
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.
-