Class WeightedPolynomialEstimator
java.lang.Object
com.irurueta.numerical.polynomials.estimators.PolynomialEstimator
com.irurueta.numerical.polynomials.estimators.WeightedPolynomialEstimator
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default number of evaluations to be weighted and taken into account.static final boolean
Indicates if weights are sorted by default so that largest weighted evaluations are used first.private int
Maximum number of evaluations to be weighted and taken into account.private boolean
Indicates if weights are sorted by default so that largest weighted evaluations are used first.private double[]
Array containing weights for all evaluations.Fields inherited from class com.irurueta.numerical.polynomials.estimators.PolynomialEstimator
DEFAULT_ESTIMATOR_TYPE, degree, evaluations, listener, locked, MIN_DEGREE
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.WeightedPolynomialEstimator
(int degree) Constructor.WeightedPolynomialEstimator
(int degree, PolynomialEstimatorListener listener) Constructor.WeightedPolynomialEstimator
(int degree, List<PolynomialEvaluation> evaluations, double[] weights) Constructor.WeightedPolynomialEstimator
(int degree, List<PolynomialEvaluation> evaluations, double[] weights, PolynomialEstimatorListener listener) Constructor.Constructor.WeightedPolynomialEstimator
(List<PolynomialEvaluation> evaluations, double[] weights) Constructor.WeightedPolynomialEstimator
(List<PolynomialEvaluation> evaluations, double[] weights, PolynomialEstimatorListener listener) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns boolean indicating whether weights have been provided and are available for retrieval.estimate()
Estimates a polynomial based on provided evaluations.int
Returns maximum number of evaluations to be weighted and taken into account.getType()
Returns type of polynomial estimator.double[]
Returns array containing a weight amount for each polynomial evaluation.private void
internalSetEvaluationsAndWeights
(List<PolynomialEvaluation> evaluations, double[] weights) Internal method to set evaluations and weights.boolean
isReady()
Indicates if this estimator is ready to start the estimation.boolean
Indicates if weights are sorted by so that largest weighted evaluations are used first.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.void
setDegreeEvaluationsAndWeights
(int degree, List<PolynomialEvaluation> evaluations, double[] weights) 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.void
setEvaluations
(List<PolynomialEvaluation> evaluations) Sets collection of polynomial evaluations and their corresponding point of evaluation used to determine a polynomial of required degree.void
setEvaluationsAndWeights
(List<PolynomialEvaluation> evaluations, double[] weights) Sets collection of polynomial evaluations along with their corresponding weights.void
setMaxEvaluations
(int maxEvaluations) Sets maximum number of evaluations to be weighted and taken into account.void
setSortWeightsEnabled
(boolean sortWeights) Specifies whether weights are sorted by so that largest weighted evaluations are used first.Methods inherited from class com.irurueta.numerical.polynomials.estimators.PolynomialEstimator
create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, create, fillDerivativeEvaluation, fillDirectEvaluation, fillIntegralEvaluation, fillIntegralIntervalEvaluation, getDegree, getEvaluations, getListener, getMinNumberOfEvaluations, getMinNumberOfEvaluations, isLocked, normalize, setDegree, setDegreeAndEvaluations, setListener
-
Field Details
-
DEFAULT_MAX_EVALUATIONS
public static final int DEFAULT_MAX_EVALUATIONSDefault number of evaluations to be weighted and taken into account.- See Also:
-
DEFAULT_SORT_WEIGHTS
public static final boolean DEFAULT_SORT_WEIGHTSIndicates if weights are sorted by default so that largest weighted evaluations are used first.- See Also:
-
maxEvaluations
private int maxEvaluationsMaximum number of evaluations to be weighted and taken into account. -
sortWeights
private boolean sortWeightsIndicates if weights are sorted by default so that largest weighted evaluations are used first. -
weights
private double[] weightsArray 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
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
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
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
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 classPolynomialEstimator
- 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
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
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 classPolynomialEstimator
- Returns:
- true if estimator is ready, false otherwise.
-
estimate
public Polynomial estimate() throws LockedException, NotReadyException, PolynomialEstimationExceptionEstimates a polynomial based on provided evaluations.- Specified by:
estimate
in classPolynomialEstimator
- Returns:
- estimated polynomial.
- Throws:
LockedException
- if estimator is locked.NotReadyException
- if estimator is not ready.PolynomialEstimationException
- if polynomial estimation fails.
-
getType
Returns type of polynomial estimator.- Specified by:
getType
in classPolynomialEstimator
- 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.
-