Package com.irurueta.numerical
Class MaximumLikelihoodEstimator
java.lang.Object
com.irurueta.numerical.MaximumLikelihoodEstimator
- Direct Known Subclasses:
AccurateMaximumLikelihoodEstimator
,HistogramMaximumLikelihoodEstimator
Abstract class to estimate the most likely value from a series of data
assumed to be normally distributed.
Assuming such condition, the subclasses of this class should be able to find
the maximum of the probability distribution of all provided input data.
Such probability distribution function is computed by aggregating all the
samples as a series of Gaussian functions with a small sigma and centered at
the exact value of the sample.
Subclasses of this class will either build a histogram of such aggregation of
Gaussians to find the most likely value, or might even find a more accurate
result by refining the maximum using a maximum detector method.
It is suggested to always use the latter (implemented as AccurateMaximumLikelihoodEstimator), as it will provide much more accurate results at a slightly higher computational cost.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Boolean indicating whether minimum and maximum values in array are already available.static final double
Default Gaussian sigma assigned to each sample.static final MaximumLikelihoodEstimatorMethod
Default method to find the most likely value.protected double
Actual Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.protected double[]
Array containing input data to be used to find the most likely value.protected boolean
Boolean indicating whether this instance is locked because some computations are being done.protected double
Maximum value found on provided input data array.static final double
Minimum allowed Gaussian sigma to be set for each sample.protected double
Minimum value found on provided input data array. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Empty constructor.protected
MaximumLikelihoodEstimator
(double gaussianSigma) Constructor.protected
MaximumLikelihoodEstimator
(double[] inputData, double gaussianSigma) Constructor.protected
MaximumLikelihoodEstimator
(double minValue, double maxValue, double[] inputData, double gaussianSigma) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns boolean indicating whether minimum and maximum values in array are already available.protected void
Internal method to compute minimum and maximum values of provided input data array.static MaximumLikelihoodEstimator
create()
Creates an instance of a subclass of this class using default maximum likelihood estimation method and default Gaussian sigma.static MaximumLikelihoodEstimator
create
(double gaussianSigma) Creates an instance of a subclass of this class using default maximum likelihood estimation method and provided Gaussian sigma.static MaximumLikelihoodEstimator
create
(double[] inputData) Creates an instance of a subclass of this class using default maximum likelihood method and Gaussian sigma, and provided input data arraystatic MaximumLikelihoodEstimator
create
(double[] inputData, double gaussianSigma) Creates an instance of a subclass of this class using default maximum likelihood method, provided Gaussian sigma and input data arraystatic MaximumLikelihoodEstimator
create
(double[] inputData, double gaussianSigma, MaximumLikelihoodEstimatorMethod method) Creates an instance of a subclass of this class based on provided method and using provided Gaussian sigma and input data array.static MaximumLikelihoodEstimator
create
(double minValue, double maxValue, double[] inputData) Creates an instance of a subclass of this class using default maximum likelihood method and default Gaussian sigma, and using provided input data array and minimum/maximum values assumed to be contained in provided array.static MaximumLikelihoodEstimator
create
(double minValue, double maxValue, double[] inputData, double gaussianSigma) Creates an instance of a subclass of this class using default maximum likelihood method and using provided Gaussian sigma, input data array and minimum/maximum values assumed to be contained in provided array.static MaximumLikelihoodEstimator
create
(double minValue, double maxValue, double[] inputData, double gaussianSigma, MaximumLikelihoodEstimatorMethod method) Creates an instance of a subclass of this class based on provided method and using provided Gaussian sigma, input data array and minimum/maximum values assumed to be contained in provided array.static MaximumLikelihoodEstimator
create
(double gaussianSigma, MaximumLikelihoodEstimatorMethod method) Creates an instance of a subclass of this class based on provided method and using provided Gaussian sigma.abstract double
estimate()
Starts the estimation of the most likely value contained within provided input data array.double
Returns Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.double[]
Returns array containing input data to be used to find the most likely value.double
Returns maximum value found on provided input data array.abstract MaximumLikelihoodEstimatorMethod
Returns method to be used for maximum likelihood estimation on subclasses of this class.double
Returns minimum value found on provided input data array.private void
internalSetGaussianSigma
(double gaussianSigma) Internal method to set Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.private void
internalSetMinMaxValues
(double minValue, double maxValue) Method to set internally minimum and maximum value found in input data array.boolean
Returns boolean indicating whether input data has already been provided or not.boolean
isLocked()
Returns boolean indicating whether this instance is locked because some computations are being done.boolean
isReady()
Returns boolean indicating if enough parameters have been provided in order to start the computation of the maximum likelihood value.void
setGaussianSigma
(double gaussianSigma) Sets Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.void
setInputData
(double[] inputData) Sets array containing input data to be used to find the most likely value.void
setInputData
(double[] inputData, double minValue, double maxValue) Sets array containing input data to be used to find the most likely value along with the minimum and maximum values assumed to be contained in it.void
setMinMaxValues
(double minValue, double maxValue) Sets minimum and maximum value assumed to be found in input data array.
-
Field Details
-
DEFAULT_GAUSSIAN_SIGMA
public static final double DEFAULT_GAUSSIAN_SIGMADefault Gaussian sigma assigned to each sample.- See Also:
-
MIN_GAUSSIAN_SIGMA
public static final double MIN_GAUSSIAN_SIGMAMinimum allowed Gaussian sigma to be set for each sample. Attempting to set Gaussian sigmas lower than this value will raise an exception.- See Also:
-
DEFAULT_METHOD
Default method to find the most likely value. By default, the accurate method is used which refines the solution found by using a histogram and a maximum detector. -
inputData
protected double[] inputDataArray containing input data to be used to find the most likely value. -
minValue
protected double minValueMinimum value found on provided input data array. -
maxValue
protected double maxValueMaximum value found on provided input data array. -
areMinMaxAvailable
protected boolean areMinMaxAvailableBoolean indicating whether minimum and maximum values in array are already available. -
locked
protected boolean lockedBoolean indicating whether this instance is locked because some computations are being done. While this instance is locked, attempting to change its status or parameters will raise an exception. -
gaussianSigma
protected double gaussianSigmaActual Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.
-
-
Constructor Details
-
MaximumLikelihoodEstimator
protected MaximumLikelihoodEstimator(double gaussianSigma) Constructor.- Parameters:
gaussianSigma
- Gaussian sigma to be used on each sample- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
MaximumLikelihoodEstimator
protected MaximumLikelihoodEstimator()Empty constructor. -
MaximumLikelihoodEstimator
protected MaximumLikelihoodEstimator(double[] inputData, double gaussianSigma) Constructor.- Parameters:
inputData
- Array containing input data where most likely value must be estimated from.gaussianSigma
- Gaussian sigma to be used on each sample.- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
MaximumLikelihoodEstimator
protected MaximumLikelihoodEstimator(double minValue, double maxValue, double[] inputData, double gaussianSigma) Constructor.- Parameters:
minValue
- Minimum value assumed to be contained within input data array.maxValue
- Maximum value assumed to be contained within input data array.inputData
- Array containing input data where most likely value must be estimated from.gaussianSigma
- Gaussian sigma to be used on each sample.- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero, or if minValue < maxValue.
-
-
Method Details
-
getMethod
Returns method to be used for maximum likelihood estimation on subclasses of this class.- Returns:
- Method for maximum likelihood estimation.
-
getMinValue
Returns minimum value found on provided input data array.- Returns:
- Minimum value found on provided input data array.
- Throws:
NotAvailableException
- Raised if this value has not yet been set or computed.
-
getMaxValue
Returns maximum value found on provided input data array.- Returns:
- Maximum value found on provided input data array.
- Throws:
NotAvailableException
- Raised if this value has not yet been set or computed.
-
setMinMaxValues
Sets minimum and maximum value assumed to be found in input data array.- Parameters:
minValue
- Minimum value in input data array.maxValue
- Maximum value in input data array.- Throws:
LockedException
- Exception raised if this instance is locked. This method can only be executed when computations finish and this instance becomes unlocked.IllegalArgumentException
- Exception raised if minValue < maxValue.
-
areMinMaxValuesAvailable
public boolean areMinMaxValuesAvailable()Returns boolean indicating whether minimum and maximum values in array are already available.- Returns:
- Boolean indicating whether minimum and maximum values in array are already available.
-
isLocked
public boolean isLocked()Returns boolean indicating whether this instance is locked because some computations are being done. While this instance is locked, attempting to change its status or parameters will raise an exception.- Returns:
- Returns boolean indicating whether this instance is locked.
-
getInputData
Returns array containing input data to be used to find the most likely value.- Returns:
- Returns array containing input data.
- Throws:
NotAvailableException
- Exception raised if input data has not yet been provided.
-
setInputData
Sets array containing input data to be used to find the most likely value.- Parameters:
inputData
- Array containing input data.- Throws:
LockedException
- Exception raised if this instance is locked. This method can only be executed when computations finish and this instance becomes unlocked.
-
setInputData
public void setInputData(double[] inputData, double minValue, double maxValue) throws LockedException Sets array containing input data to be used to find the most likely value along with the minimum and maximum values assumed to be contained in it.- Parameters:
inputData
- Array containing input data.minValue
- Minimum value assumed to be contained in provided input data array.maxValue
- Maximum value assumed to be contained in provided input data array.- Throws:
LockedException
- Exception raised if this instance is locked. This method can only be executed when computations finish and this instance becomes unlocked.IllegalArgumentException
- Exception raised if minValue < maxValue.
-
isInputDataAvailable
public boolean isInputDataAvailable()Returns boolean indicating whether input data has already been provided or not.- Returns:
- True if input data is available and can be retrieved.
-
isReady
public boolean isReady()Returns boolean indicating if enough parameters have been provided in order to start the computation of the maximum likelihood value. Usually providing input data is enough to make this instance ready, but this is dependent of specific implementations of subclasses.- Returns:
- True if this instance is ready to start the computation of the maximum likelihood value.
-
getGaussianSigma
public double getGaussianSigma()Returns Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.- Returns:
- Gaussian sigma to be used on each sample.
-
setGaussianSigma
Sets Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.- Parameters:
gaussianSigma
- Gaussian sigma to be used on each sample.- Throws:
LockedException
- Exception raised if this instance is locked. This method can only be executed when computations finish and this instance becomes unlockedIllegalArgumentException
- Exception raised if provided Gaussian sigma is negative or zero.
-
estimate
Starts the estimation of the most likely value contained within provided input data array.- Returns:
- The most likely value.
- Throws:
LockedException
- Exception raised if this instance is locked. This method can only be executed when computations finish and this instance becomes unlocked.NotReadyException
- Exception raised if this instance is not yet ready- See Also:
-
create
public static MaximumLikelihoodEstimator create(double gaussianSigma, MaximumLikelihoodEstimatorMethod method) Creates an instance of a subclass of this class based on provided method and using provided Gaussian sigma.- Parameters:
gaussianSigma
- Gaussian sigma to be set for each sample.method
- Method to estimate maximum likelihood value.- Returns:
- A maximum likelihood estimator.
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
create
Creates an instance of a subclass of this class using default maximum likelihood estimation method and provided Gaussian sigma.- Parameters:
gaussianSigma
- Gaussian sigma to be set for each sample.- Returns:
- A maximum likelihood estimator.
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
create
Creates an instance of a subclass of this class using default maximum likelihood estimation method and default Gaussian sigma.- Returns:
- A maximum likelihood estimator.
-
create
public static MaximumLikelihoodEstimator create(double[] inputData, double gaussianSigma, MaximumLikelihoodEstimatorMethod method) Creates an instance of a subclass of this class based on provided method and using provided Gaussian sigma and input data array.- Parameters:
inputData
- Array containing input data to be used for the estimation of the maximum likelihood value.gaussianSigma
- Gaussian sigma to be set for each sample.method
- Method to estimate maximum likelihood value- Returns:
- A maximum likelihood estimator.
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
create
Creates an instance of a subclass of this class using default maximum likelihood method, provided Gaussian sigma and input data array- Parameters:
inputData
- Array containing input data to be used for the estimation of the maximum likelihood value.gaussianSigma
- Gaussian sigma to be set for each sample.- Returns:
- A maximum likelihood estimator
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
create
Creates an instance of a subclass of this class using default maximum likelihood method and Gaussian sigma, and provided input data array- Parameters:
inputData
- Array containing input data to be used for the estimation of the maximum likelihood value.- Returns:
- A maximum likelihood estimator
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero.
-
create
public static MaximumLikelihoodEstimator create(double minValue, double maxValue, double[] inputData, double gaussianSigma, MaximumLikelihoodEstimatorMethod method) Creates an instance of a subclass of this class based on provided method and using provided Gaussian sigma, input data array and minimum/maximum values assumed to be contained in provided array.- Parameters:
minValue
- Minimum value assumed to be contained in input data arraymaxValue
- Maximum value assumed to be contained in input data arrayinputData
- Array containing input data to be used for the estimation of the maximum likelihood value.gaussianSigma
- Gaussian sigma to be set for each sample.method
- Method to estimate maximum likelihood value- Returns:
- A maximum likelihood estimator
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero, or if minValue < maxValue.
-
create
public static MaximumLikelihoodEstimator create(double minValue, double maxValue, double[] inputData, double gaussianSigma) Creates an instance of a subclass of this class using default maximum likelihood method and using provided Gaussian sigma, input data array and minimum/maximum values assumed to be contained in provided array.- Parameters:
minValue
- Minimum value assumed to be contained in input data arraymaxValue
- Maximum value assumed to be contained in input data arrayinputData
- Array containing input data to be used for the estimation of the maximum likelihood value.gaussianSigma
- Gaussian sigma to be set for each sample.- Returns:
- A maximum likelihood estimator
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero, or if minValue < maxValue.
-
create
public static MaximumLikelihoodEstimator create(double minValue, double maxValue, double[] inputData) Creates an instance of a subclass of this class using default maximum likelihood method and default Gaussian sigma, and using provided input data array and minimum/maximum values assumed to be contained in provided array.- Parameters:
minValue
- Minimum value assumed to be contained in input data arraymaxValue
- Maximum value assumed to be contained in input data arrayinputData
- Array containing input data to be used for the estimation of the maximum likelihood value.- Returns:
- A maximum likelihood estimator
- Throws:
IllegalArgumentException
- Raised if provided Gaussian sigma is negative or zero, or if minValue < maxValue.
-
computeMinMaxValues
protected void computeMinMaxValues()Internal method to compute minimum and maximum values of provided input data array. -
internalSetMinMaxValues
private void internalSetMinMaxValues(double minValue, double maxValue) Method to set internally minimum and maximum value found in input data array.- Parameters:
minValue
- Minimum value in input data array.maxValue
- Maximum value in input data array.- Throws:
IllegalArgumentException
- Exception raised if minValue < maxValue.
-
internalSetGaussianSigma
private void internalSetGaussianSigma(double gaussianSigma) Internal method to set Gaussian sigma to be used on each sample when aggregating Gaussian functions centered at each input data sample value.- Parameters:
gaussianSigma
- Gaussian sigma to be used on each sample.- Throws:
IllegalArgumentException
- Exception raised if provided Gaussian sigma is negative or zero.
-