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.

public class MSACRobustEstimator<T> extends RobustEstimator<T>
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.
  • Field Details

    • DEFAULT_CONFIDENCE

      public static final double DEFAULT_CONFIDENCE
      Constant 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_ITERATIONS
      Default maximum allowed number of iterations.
      See Also:
    • MIN_CONFIDENCE

      public static final double MIN_CONFIDENCE
      Minimum allowed confidence value.
      See Also:
    • MAX_CONFIDENCE

      public static final double MAX_CONFIDENCE
      Maximum allowed confidence value.
      See Also:
    • MIN_ITERATIONS

      public static final int MIN_ITERATIONS
      Minimum allowed number of iterations.
      See Also:
    • MIN_THRESHOLD

      public static final double MIN_THRESHOLD
      Minimum allowed threshold to determine inliers.
      See Also:
    • confidence

      private double confidence
      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.
    • maxIterations

      private int maxIterations
      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.
    • subsetSelector

      private SubsetSelector subsetSelector
      Instance in charge of picking random subsets of samples.
    • iters

      private int iters
      Number of iterations to be done to obtain required confidence.
    • bestResult

      private T bestResult
      Best solution that has been found so far during an estimation.
    • bestResultInliersData

      private MSACRobustEstimator.MSACInliersData bestResultInliersData
      Data related to inliers found for best result.
    • bestNumberInliersData

      private MSACRobustEstimator.MSACInliersData bestNumberInliersData
      Data related to solution producing the largest number of inliers.
  • Constructor Details

    • MSACRobustEstimator

      public MSACRobustEstimator()
      Constructor.
    • MSACRobustEstimator

      public MSACRobustEstimator(MSACRobustEstimatorListener<T> listener)
      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

      public void setConfidence(double confidence) throws LockedException
      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

      public void setMaxIterations(int maxIterations) throws LockedException
      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

      public T 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

      public MSACRobustEstimator.MSACInliersData getBestResultInliersData()
      Returns data related to the best inliers found for best result.
      Returns:
      data related to inliers found for best result.
    • getBestNumberInliersData

      public MSACRobustEstimator.MSACInliersData 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 class RobustEstimator<T>
      Returns:
      true if ready, false otherwise.
    • estimate

      Robustly estimates an instance of T.
      Specified by:
      estimate in 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).
    • getInliersData

      public InliersData getInliersData()
      Returns data about inliers once estimation has been done.
      Specified by:
      getInliersData in class RobustEstimator<T>
      Returns:
      data about inliers or null if estimation has not been done.
    • getMethod

      public RobustEstimatorMethod getMethod()
      Returns method being used for robust estimation.
      Specified by:
      getMethod in class RobustEstimator<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