Class WeightedPolynomialEstimator

java.lang.Object
com.irurueta.numerical.polynomials.estimators.PolynomialEstimator
com.irurueta.numerical.polynomials.estimators.WeightedPolynomialEstimator

public class WeightedPolynomialEstimator extends PolynomialEstimator
This class implements a polynomial estimator using weighted evaluations. Weights can be used so that evaluations assumed to have a better quality (i.e. more precisely estimated) are considered to be more relevant. It is discouraged to use a large number of evaluations, even if they are correctly weighted, since as the number of evaluations increase so do the rounding errors.
  • Field Details

    • DEFAULT_MAX_EVALUATIONS

      public static final int DEFAULT_MAX_EVALUATIONS
      Default number of evaluations to be weighted and taken into account.
      See Also:
    • DEFAULT_SORT_WEIGHTS

      public static final boolean DEFAULT_SORT_WEIGHTS
      Indicates if weights are sorted by default so that largest weighted evaluations are used first.
      See Also:
    • maxEvaluations

      private int maxEvaluations
      Maximum number of evaluations to be weighted and taken into account.
    • sortWeights

      private boolean sortWeights
      Indicates if weights are sorted by default so that largest weighted evaluations are used first.
    • weights

      private double[] weights
      Array containing weights for all evaluations.
  • Constructor Details

    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator()
      Constructor.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(int degree)
      Constructor.
      Parameters:
      degree - degree of polynomial to be estimated.
      Throws:
      IllegalArgumentException - if provided degree is less than 1.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(List<PolynomialEvaluation> evaluations, double[] weights)
      Constructor.
      Parameters:
      evaluations - collection of polynomial evaluations.
      weights - array containing a weight amount for each evaluation. The larger the value of a weight, the most significant the correspondence will be.
      Throws:
      IllegalArgumentException - if evaluations or weights are null or don't have the same size.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(PolynomialEstimatorListener listener)
      Constructor.
      Parameters:
      listener - listener to be notified of events.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(int degree, List<PolynomialEvaluation> evaluations, double[] weights)
      Constructor.
      Parameters:
      degree - degree of polynomial to be estimated.
      evaluations - collection of polynomial evaluations.
      weights - array containing a weight amount for each evaluation. The larger the value of a weight, the most significant the correspondence will be.
      Throws:
      IllegalArgumentException - if evaluations or weights are null or don't have the same size, or if provided degree is less than 1.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(int degree, PolynomialEstimatorListener listener)
      Constructor.
      Parameters:
      degree - degree of polynomial to be estimated.
      listener - listener to be notified of events.
      Throws:
      IllegalArgumentException - if provided degree is less than 1.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(List<PolynomialEvaluation> evaluations, double[] weights, PolynomialEstimatorListener listener)
      Constructor.
      Parameters:
      evaluations - collection of polynomial evaluations.
      weights - array containing a weight amount for each evaluation. The larger the value of a weight, the most significant the correspondence will be.
      listener - listener to be notified of events.
      Throws:
      IllegalArgumentException - if evaluations or weights are null or don't have the same size.
    • WeightedPolynomialEstimator

      public WeightedPolynomialEstimator(int degree, List<PolynomialEvaluation> evaluations, double[] weights, PolynomialEstimatorListener listener)
      Constructor.
      Parameters:
      degree - degree of polynomial to be estimated.
      evaluations - collection of polynomial evaluations.
      weights - array containing a weight amount for each evaluation. The larger the value of a weight, the most significant the correspondence will be.
      listener - listener to be notified of events.
      Throws:
      IllegalArgumentException - if evaluations or weights are null or don't have the same size, or if provided degree is less than 1.
  • Method Details

    • setEvaluations

      public void setEvaluations(List<PolynomialEvaluation> evaluations)
      Sets collection of polynomial evaluations and their corresponding point of evaluation used to determine a polynomial of required degree. This method override always throws an IllegalArgumentException because it is expected to provide both evaluations and their weights.
      Overrides:
      setEvaluations in class PolynomialEstimator
      Parameters:
      evaluations - collection of polynomial evaluations.
      Throws:
      IllegalArgumentException - always thrown.
    • setEvaluationsAndWeights

      public void setEvaluationsAndWeights(List<PolynomialEvaluation> evaluations, double[] weights) throws LockedException
      Sets collection of polynomial evaluations along with their corresponding weights.
      Parameters:
      evaluations - collection of polynomial evaluations.
      weights - array containing a weight amount for each polynomial evaluation. The larger the value of a weight, the most significant the evaluation will be.
      Throws:
      LockedException - if estimator is locked.
      IllegalArgumentException - if evaluations or weights are null or don't have the same size.
    • setDegreeEvaluationsAndWeights

      public void setDegreeEvaluationsAndWeights(int degree, List<PolynomialEvaluation> evaluations, double[] weights) throws LockedException
      Sets degree of polynomial to be estimated and collection of polynomial evaluations and their corresponding point of evaluation used to determine a polynomial of specified degree.
      Parameters:
      degree - degree of polynomial to be estimated.
      evaluations - collection of polynomial evaluations.
      weights - array containing a weight amount for each polynomial evaluation. The larger the value of a weight, the most significant the evaluation will be.
      Throws:
      IllegalArgumentException - if provided degree is less than 1 or if evaluations or weights are null or don't have the same size.
      LockedException - if this instance is locked.
    • getWeights

      public double[] getWeights()
      Returns array containing a weight amount for each polynomial evaluation. The larger the value of a weight, the most significant the correspondence will be.
      Returns:
      array containing weights for each correspondence.
    • areWeightsAvailable

      public boolean areWeightsAvailable()
      Returns boolean indicating whether weights have been provided and are available for retrieval.
      Returns:
      true if weights are available, false otherwise.
    • getMaxEvaluations

      public int getMaxEvaluations()
      Returns maximum number of evaluations to be weighted and taken into account.
      Returns:
      maximum number of evaluations to be weighted.
    • setMaxEvaluations

      public void setMaxEvaluations(int maxEvaluations) throws LockedException
      Sets maximum number of evaluations to be weighted and taken into account. This method must be called after setting degree, because the minimum number of required evaluations will be checked based on degree of polynomial to be estimated.
      Parameters:
      maxEvaluations - maximum number of evaluations to be weighted.
      Throws:
      IllegalArgumentException - if provided value is less than the minimum number of required evaluations.
      LockedException - if this instance is locked.
    • isSortWeightsEnabled

      public boolean isSortWeightsEnabled()
      Indicates if weights are sorted by so that largest weighted evaluations are used first.
      Returns:
      true if weights are sorted, false otherwise.
    • setSortWeightsEnabled

      public void setSortWeightsEnabled(boolean sortWeights) throws LockedException
      Specifies whether weights are sorted by so that largest weighted evaluations are used first.
      Parameters:
      sortWeights - true if weights are sorted, false otherwise.
      Throws:
      LockedException - if this instance is locked.
    • isReady

      public boolean isReady()
      Indicates if this estimator is ready to start the estimation. Estimator will be ready once enough evaluations and weights are provided.
      Overrides:
      isReady in class PolynomialEstimator
      Returns:
      true if estimator is ready, false otherwise.
    • estimate

      Estimates a polynomial based on provided evaluations.
      Specified by:
      estimate in class PolynomialEstimator
      Returns:
      estimated polynomial.
      Throws:
      LockedException - if estimator is locked.
      NotReadyException - if estimator is not ready.
      PolynomialEstimationException - if polynomial estimation fails.
    • getType

      public PolynomialEstimatorType getType()
      Returns type of polynomial estimator.
      Specified by:
      getType in class PolynomialEstimator
      Returns:
      type of polynomial estimator.
    • normalize

      private static void normalize(com.irurueta.algebra.Matrix a, com.irurueta.algebra.Matrix b, int row, double weight)
      Normalizes rows of system matrix and values matrix to increase accuracy of linear system of equations to be solved.
      Parameters:
      a - system matrix.
      b - values matrix.
      row - row to normalize.
      weight - weight.
    • internalSetEvaluationsAndWeights

      private void internalSetEvaluationsAndWeights(List<PolynomialEvaluation> evaluations, double[] weights)
      Internal method to set evaluations and weights.
      Parameters:
      evaluations - evaluations.
      weights - weights.
      Throws:
      IllegalArgumentException - if evaluations or weights are null or don't have the same size.