Package com.irurueta.numerical.robust
Class PROSACRobustEstimator<T>
java.lang.Object
com.irurueta.numerical.robust.RobustEstimator<T>
com.irurueta.numerical.robust.PROSACRobustEstimator<T>
- Type Parameters:
- T- type of object to be estimated.
This class implements PROSAC (PROgressive random SAmple Consensus) algorithm
 to robustly estimate a data model.
 This algorithm is an improvement over RANSAC that can be used whenever a
 certain measure of quality is known for each sample of data.
 The measure of quality does not need to be precise, only needs to give a
 certain idea whether a given sample is likely to be better than another one
 (by having a higher quality score).
 Whenever RANSAC is being used but quality of measures is known, PROSAC should
 be used instead, since this algorithm offers a result with a comparable
 precision to that obtained with RANSAC but having a much smaller
 computational cost.
 The large improvement in computational cost is achieved thanks to the fact
 that by taking into account the quality measures, sub-samples can be
 prioritized so that more likely to be inliers are picked first.
 
This implementation is based on: http://devernay.free.fr/vision/src/prosac.c
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classContains data related to estimated inliers.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionData related to inliers found for best result.private TBest solution that has been found so far during an estimation.private doublebeta is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface.static final doubleChi squared.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 doubleDefines the default value for beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface.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 doubleDefines the default value for the maximum probability that a solution with more than inliersNStar in U_nStar exist and was not found after k samples.static final intDefault maximum allowed number of iterations.static final doubleDefault maximum allowed outliers proportion in the input data.private doubleeta0 is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).static final doubleMaximum allowed value for beta.static final doubleMaximum allowed confidence value.static final doubleMaximum allowed value for eta0.static final doubleMaximum allowed value for maximum allowed outliers proportion in the input dataprivate intMaximum allowed number of iterations.private doubleIn this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set.static final doubleMinimum allowed value for beta.static final doubleMinimum allowed confidence value.static final doubleMinimum allowed value for eta0.static final intMinimum allowed number of iterations.static final doubleMinimum allowed value for maximum allowed outliers proportion in the input data.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.RobustEstimatorDEFAULT_PROGRESS_DELTA, listener, locked, MAX_PROGRESS_DELTA, MIN_PROGRESS_DELTA, progressDelta
- 
Constructor SummaryConstructorsConstructorDescriptionConstructor.PROSACRobustEstimator(PROSACRobustEstimatorListener<T> listener) Constructor with listener.
- 
Method SummaryModifier and TypeMethodDescriptionprivate static <T> intcomputeInliers(T iterResult, double threshold, BitSet inliers, int totalSamples, PROSACRobustEstimatorListener<T> listener, double[] residuals) Computes inliers data for current iteration.private static intcomputeIterations(double probInlier, int subsetSize, double confidence) Computes number of required iterations to achieve required confidence with current probability of inlier and sample subset size.private static int[]computeSortedQualityIndices(double[] qualityScores) Obtains indices of samples corresponding to samples ordered in descending quality scores.estimate()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.doublegetBeta()Returns beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface.doubleReturns amount of confidence expressed as a value between 0 and 1.0 (which is equivalent to 100%).doublegetEta0()Return eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).Returns data about inliers once estimation has been done.intMaximum allowed number of iterations.doubleReturns maximum allowed outliers proportion in the input data.Returns method being used for robust estimation.intReturns number of iterations to be done to obtain required confidence.private static intimin(int subsetSize, int sampleSize, double beta) Non randomness states that i-m (where i is the cardinal of the set of inliers for a wrong model) follows the binomial distribution B(n,beta).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.private static voidreverse(int[] array) Reverses provided array.voidsetBeta(double beta) Sets beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface.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%).voidsetEta0(double eta0) Sets eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).voidsetMaxIterations(int maxIterations) Sets maximum allowed number of iterations.voidsetMaxOutliersProportion(double maxOutliersProportion) Sets maximum allowed outliers proportion in the input data.private static voidtransformIndices(int[] subsetIndices, int[] sortedIndices, int[] transformedSubsetIndices) Transforms indices picked by the subset selector into the indices where samples are actually localed by taking into account their original position before sorting quality scores.Methods inherited from class com.irurueta.numerical.robust.RobustEstimatorgetListener, getProgressDelta, isListenerAvailable, isLocked, setListener, setProgressDelta
- 
Field Details- 
DEFAULT_CONFIDENCEpublic 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_ITERATIONSpublic static final int DEFAULT_MAX_ITERATIONSDefault maximum allowed number of iterations.- See Also:
 
- 
MIN_CONFIDENCEpublic static final double MIN_CONFIDENCEMinimum allowed confidence value.- See Also:
 
- 
MAX_CONFIDENCEpublic static final double MAX_CONFIDENCEMaximum allowed confidence value.- See Also:
 
- 
MIN_ITERATIONSpublic static final int MIN_ITERATIONSMinimum allowed number of iterations.- See Also:
 
- 
MIN_THRESHOLDpublic static final double MIN_THRESHOLDMinimum allowed threshold to determine inliers.- See Also:
 
- 
DEFAULT_MAX_OUTLIERS_PROPORTIONpublic static final double DEFAULT_MAX_OUTLIERS_PROPORTIONDefault maximum allowed outliers proportion in the input data. This is used do determine the number of required iterations.- See Also:
 
- 
MIN_MAX_OUTLIERS_PROPORTIONpublic static final double MIN_MAX_OUTLIERS_PROPORTIONMinimum allowed value for maximum allowed outliers proportion in the input data.- See Also:
 
- 
MAX_MAX_OUTLIERS_PROPORTIONpublic static final double MAX_MAX_OUTLIERS_PROPORTIONMaximum allowed value for maximum allowed outliers proportion in the input data- See Also:
 
- 
DEFAULT_ETA0public static final double DEFAULT_ETA0Defines the default value for the maximum probability that a solution with more than inliersNStar in U_nStar exist and was not found after k samples.- See Also:
 
- 
MIN_ETA0public static final double MIN_ETA0Minimum allowed value for eta0.- See Also:
 
- 
MAX_ETA0public static final double MAX_ETA0Maximum allowed value for eta0.- See Also:
 
- 
DEFAULT_BETApublic static final double DEFAULT_BETADefines the default value for beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96*s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image.- See Also:
 
- 
MIN_BETApublic static final double MIN_BETAMinimum allowed value for beta.- See Also:
 
- 
MAX_BETApublic static final double MAX_BETAMaximum allowed value for beta.- See Also:
 
- 
CHI_SQUAREDpublic static final double CHI_SQUAREDChi squared.- See Also:
 
- 
DEFAULT_COMPUTE_AND_KEEP_INLIERSpublic 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_RESIDUALSpublic static final boolean DEFAULT_COMPUTE_AND_KEEP_RESIDUALSIndicates that by default residuals will only be computed but not kept.- See Also:
 
- 
confidenceprivate 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.
- 
maxIterationsprivate 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.
- 
maxOutliersProportionprivate double maxOutliersProportionIn this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set. Maximum allowed outliers proportion in the input data: used to compute nIters (can be as high as 0.95).
- 
eta0private double eta0eta0 is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).
- 
betaprivate double betabeta is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image YOU MUST ADJUST THIS VALUE, DEPENDING ON YOUR PROBLEM!
- 
subsetSelectorInstance in charge of picking random subsets of samples.
- 
nItersprivate int nItersNumber of iterations to be done to obtain required confidence.
- 
bestResultBest solution that has been found so far during an estimation.
- 
bestInliersDataData related to inliers found for best result.
- 
computeAndKeepInliersprivate boolean computeAndKeepInliersIndicates whether inliers must be computed and kept.
- 
computeAndKeepResidualsprivate boolean computeAndKeepResidualsIndicates whether residuals must be computed and kept.
 
- 
- 
Constructor Details- 
PROSACRobustEstimatorpublic PROSACRobustEstimator()Constructor.
- 
PROSACRobustEstimatorConstructor 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- 
getConfidencepublic 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.
 
- 
setConfidenceSets 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.
 
- 
getMaxIterationspublic 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.
 
- 
setMaxIterationsSets 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.
 
- 
getMaxOutliersProportionpublic double getMaxOutliersProportion()Returns maximum allowed outliers proportion in the input data. This is used to compute number of iterations to be done (nIters). It typically can be as high as 0.95. Higher values, up to 1 are possible but not recommended. In this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set.- Returns:
- maximum allowed outliers proportion in the input data.
 
- 
setMaxOutliersProportionSets maximum allowed outliers proportion in the input data. This is used to compute number of iterations to be done (nIters). It typically can be as high as 0.95. Higher values, up to 1 are possible but not recommended. In this implementation, PROSAC won't stop before having reached the corresponding inliers rate on the complete data set.- Parameters:
- maxOutliersProportion- maximum allowed outliers proportion in the input data.
- Throws:
- IllegalArgumentException- if provided value is less than 0.0 or greater than 1.0.
- LockedException- if this estimator is locked because an estimation is being computed.
 
- 
getEta0public double getEta0()Return eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).- Returns:
- eta0 value.
 
- 
setEta0Sets eta0, which is the maximum probability that a solution with more than inliersNStar inliers in U_nStar exists and was not found after k samples (typically set to 5%).- Parameters:
- eta0- eta0 value to be set.
- Throws:
- IllegalArgumentException- if provided value is less than 0.0 or greater than 1.0.
- LockedException- if this estimator is locked because an estimation is being computed.
 
- 
getBetapublic double getBeta()Returns beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image YOU MUST ADJUST THIS VALUE, DEPENDING ON YOUR PROBLEM!- Returns:
- beta value.
 
- 
setBetaSets beta, which is the probability that a match is declared inlier by mistake, i.e. the ratio of the "inlier" surface by the total surface. The inlier surface is a disc with radius 1.96s for homography/displacement computation, or a band with width 1.96s*2 for epipolar geometry (s is the detection noise), and the total surface is the surface of the image YOU MUST ADJUST THIS VALUE, DEPENDING ON YOUR PROBLEM!- Parameters:
- beta- beta value to be set.
- Throws:
- IllegalArgumentException- if provided value is less than 0.0 or greater than 1.0.
- LockedException- if this estimator is locked because an estimation is being computed.
 
- 
getNIterspublic int getNIters()Returns number of iterations to be done to obtain required confidence. This does not need to be equal to the actual number of iterations the algorithm finally required to obtain a solution.- Returns:
- number of iterations to be done to obtain required confidence.
 
- 
getBestResultReturns best solution that has been found so far during an estimation.- Returns:
- best solution that has been found so far during an estimation.
 
- 
getBestInliersDataGets data related to inliers found for best result.- Returns:
- data related to inliers found for best result.
 
- 
isComputeAndKeepInliersEnabledpublic 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.
 
- 
setComputeAndKeepInliersEnabledSpecifies 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.
 
- 
isComputeAndKeepResidualsEnabledpublic 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.
 
- 
setComputeAndKeepResidualsEnabledpublic 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.
 
- 
isReadypublic boolean isReady()Indicates if estimator is ready to start the estimation process.- Overrides:
- isReadyin class- RobustEstimator<T>
- Returns:
- true if ready, false otherwise.
 
- 
estimateRobustly estimates an instance of T.- Specified by:
- estimatein class- RobustEstimator<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).
 
- 
getInliersDataReturns data about inliers once estimation has been done.- Specified by:
- getInliersDatain class- RobustEstimator<T>
- Returns:
- data about inliers or null if estimation has not been done.
 
- 
getMethodReturns method being used for robust estimation.- Specified by:
- getMethodin class- RobustEstimator<T>
- Returns:
- method being used for robust estimation.
 
- 
transformIndicesprivate static void transformIndices(int[] subsetIndices, int[] sortedIndices, int[] transformedSubsetIndices) Transforms indices picked by the subset selector into the indices where samples are actually localed by taking into account their original position before sorting quality scores.- Parameters:
- subsetIndices- indices picked by the subset selector. These are positions after sorting. Must have the subset length.
- sortedIndices- indices relating sorted positions to their original positions. Each position i-th in the array refers to the original position before sorting. Must have the number of samples length.
- transformedSubsetIndices- array where result is stored. Must have the subset length.
 
- 
computeInliersprivate static <T> int computeInliers(T iterResult, double threshold, BitSet inliers, int totalSamples, PROSACRobustEstimatorListener<T> listener, double[] residuals) 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.
- inliers- bitset indicating which samples are inliers. This is indicated in their original position before sorting.
- totalSamples- total number of samples.
- listener- listener to obtain residuals for samples.
- residuals- array where residuals must be stored (if provided).
- Returns:
- inliers data.
 
- 
computeSortedQualityIndicesprivate static int[] computeSortedQualityIndices(double[] qualityScores) throws com.irurueta.sorting.SortingException Obtains indices of samples corresponding to samples ordered in descending quality scores.- Parameters:
- qualityScores- quality scores associated to each sample to be used to obtain indices to sort samples in descending order of quality values.
- Returns:
- indices to sort samples in descending order of quality values.
- Throws:
- com.irurueta.sorting.SortingException- if sorting fails.
 
- 
reverseprivate static void reverse(int[] array) Reverses provided array.- Parameters:
- array- array to be reversed.
 
- 
computeIterationsprivate static int computeIterations(double probInlier, int subsetSize, double confidence) Computes number of required iterations to achieve required confidence with current probability of inlier and sample subset size.- Parameters:
- probInlier- probability of inlier.
- subsetSize- sample subset size.
- confidence- required confidence of result.
- Returns:
- number of required iterations.
 
- 
iminprivate static int imin(int subsetSize, int sampleSize, double beta) Non randomness states that i-m (where i is the cardinal of the set of inliers for a wrong model) follows the binomial distribution B(n,beta). For n big enough, B(n,beta) approximates to normal distribution N(mu, sigma^2) by the central limit theorem, with mu = n*beta and sigma = sqrt(n*beta*(1 - beta)). Psi, the probability that In_star out of n_star data points are by chance inliers to an arbitrary incorrect model, is set to 0.05 (5%, as in the original paper), and you must change the Chi2 value if you chose a different value for psi.- Parameters:
- subsetSize- sample subset size.
- sampleSize- total number of samples.
- beta- beta value.
- Returns:
- i-m.
 
 
-