Class MaximumLikelihoodEstimator

java.lang.Object
com.irurueta.numerical.MaximumLikelihoodEstimator
Direct Known Subclasses:
AccurateMaximumLikelihoodEstimator, HistogramMaximumLikelihoodEstimator

public abstract class MaximumLikelihoodEstimator extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Boolean indicating whether minimum and maximum values in array are already available.
    static final double
    Default Gaussian sigma assigned to each sample.
    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

    Constructors
    Modifier
    Constructor
    Description
    protected
    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 Type
    Method
    Description
    boolean
    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.
    Creates an instance of a subclass of this class using default maximum likelihood estimation method and default Gaussian sigma.
    create(double gaussianSigma)
    Creates an instance of a subclass of this class using default maximum likelihood estimation method and provided Gaussian sigma.
    create(double[] inputData)
    Creates an instance of a subclass of this class using default maximum likelihood method and Gaussian sigma, and provided input data array
    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 array
    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.
    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.
    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.
    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.
    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
    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.
    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
    Returns boolean indicating whether this instance is locked because some computations are being done.
    boolean
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_GAUSSIAN_SIGMA

      public static final double DEFAULT_GAUSSIAN_SIGMA
      Default Gaussian sigma assigned to each sample.
      See Also:
    • MIN_GAUSSIAN_SIGMA

      public static final double MIN_GAUSSIAN_SIGMA
      Minimum 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

      public static final MaximumLikelihoodEstimatorMethod 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[] inputData
      Array containing input data to be used to find the most likely value.
    • minValue

      protected double minValue
      Minimum value found on provided input data array.
    • maxValue

      protected double maxValue
      Maximum value found on provided input data array.
    • areMinMaxAvailable

      protected boolean areMinMaxAvailable
      Boolean indicating whether minimum and maximum values in array are already available.
    • locked

      protected boolean locked
      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.
    • gaussianSigma

      protected double gaussianSigma
      Actual 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

      public abstract MaximumLikelihoodEstimatorMethod getMethod()
      Returns method to be used for maximum likelihood estimation on subclasses of this class.
      Returns:
      Method for maximum likelihood estimation.
    • getMinValue

      public double getMinValue() throws NotAvailableException
      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

      public double getMaxValue() throws NotAvailableException
      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

      public void setMinMaxValues(double minValue, double maxValue) throws LockedException
      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

      public double[] getInputData() throws NotAvailableException
      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

      public void setInputData(double[] inputData) throws LockedException
      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

      public void setGaussianSigma(double gaussianSigma) throws LockedException
      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 unlocked
      IllegalArgumentException - Exception raised if provided Gaussian sigma is negative or zero.
    • estimate

      public abstract double estimate() throws LockedException, NotReadyException
      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

      public static MaximumLikelihoodEstimator create(double gaussianSigma)
      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

      public static MaximumLikelihoodEstimator 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

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

      public 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 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 array
      maxValue - Maximum value assumed to be contained in input data array
      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, 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 array
      maxValue - Maximum value assumed to be contained in input data array
      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, 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 array
      maxValue - Maximum value assumed to be contained in input data array
      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, 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.