Class HistogramMaximumLikelihoodEstimator

java.lang.Object
com.irurueta.numerical.MaximumLikelihoodEstimator
com.irurueta.numerical.HistogramMaximumLikelihoodEstimator

public class HistogramMaximumLikelihoodEstimator extends MaximumLikelihoodEstimator
Class to estimate the most likely value from a series of samples assumed to be normally distributed. This implementation will compute a histogram of the probability distribution function of all the provided samples. The 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.
  • Field Details

    • DEFAULT_NUMBER_OF_BINS

      public static final int DEFAULT_NUMBER_OF_BINS
      Default number of bins to be used on the histogram.
      See Also:
    • MIN_NUMBER_OF_BINS

      public static final int MIN_NUMBER_OF_BINS
      Minimum number of bins allowed on the histogram.
      See Also:
    • EPS

      public static final double EPS
      Value to be considered as the machine precision.
      See Also:
    • numberOfBins

      private int numberOfBins
      Number of bins to be used on the histogram. The larger the value the more precise results will be but more data will be needed to obtain statistically meaningful data so that enough samples are present on each bin.
    • bins

      private double[] bins
      Number of samples contained on each bin. The number of samples is not an integer because the Gaussians of each sample will only have a value equal to one on their respective centers, but at other locations, only the fractional part is added to each bin. Using Gaussians on each sample behave as an interpolation of the location of each sample around a certain value.
    • gaussian

      private double[] gaussian
      Array containing the Gaussian values corresponding to each bin for a single sample. The values of each array are updated for each sample and aggregated to the values of the bins array.
  • Constructor Details

    • HistogramMaximumLikelihoodEstimator

      public HistogramMaximumLikelihoodEstimator()
      Empty constructor.
    • HistogramMaximumLikelihoodEstimator

      public HistogramMaximumLikelihoodEstimator(double gaussianSigma, int numberOfBins)
      Constructor.
      Parameters:
      gaussianSigma - Gaussian sigma to be used on each sample.
      numberOfBins - Number of bins to be used on the histogram.
      Throws:
      IllegalArgumentException - Raised if provided Gaussian sigma is negative or zero, or if provided number of bins is smaller than the minimum allowed number of bins.
    • HistogramMaximumLikelihoodEstimator

      public HistogramMaximumLikelihoodEstimator(double[] inputData, double gaussianSigma, int numberOfBins)
      Constructor.
      Parameters:
      inputData - Array containing input data where most likely value must be estimated from.
      gaussianSigma - Gaussian sigma to be used on each sample.
      numberOfBins - Number of bins to be used on the histogram.
      Throws:
      IllegalArgumentException - Raised if provided Gaussian sigma is negative or zero, or if provided number of bins is smaller than the minimum allowed number of bins.
    • HistogramMaximumLikelihoodEstimator

      public HistogramMaximumLikelihoodEstimator(double minValue, double maxValue, double[] inputData, double gaussianSigma, int numberOfBins)
      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.
      numberOfBins - Number of bins to be used on the histogram.
      Throws:
      IllegalArgumentException - Raised if provided Gaussian sigma is negative or zero, or if provided number of bins is smaller than the minimum allowed number of bins or if minValue < maxValue.
  • Method Details

    • getMethod

      Returns method to be used for maximum likelihood estimation, which for this class is MaximumLikelihoodEstimatorMethod. HISTOGRAM_MAXIMUM_LIKELIHOOD_ESTIMATOR.
      Specified by:
      getMethod in class MaximumLikelihoodEstimator
      Returns:
      Method for maximum likelihood estimation.
    • getNumberOfBins

      public int getNumberOfBins()
      Returns number of bins to be used on the histogram. The larger the value the more precise results will be but more data will be needed to obtain statistically meaningful data so that enough samples are present on each bin.
      Returns:
      Number of bins to be used on the histogram.
    • setNumberOfBins

      public void setNumberOfBins(int numberOfBins) throws LockedException
      Sets number of bins to be used on the histogram. The larger the provided value being set the more precise results will be but more data will be needed to obtain statistically meaningful data so that enough samples are present on each bin.
      Parameters:
      numberOfBins - Number of bins to be used on the histogram.
      Throws:
      LockedException - Exception raised if this instance is locked. This method can only be executed when computations finish and this instance becomes unlocked.
      IllegalArgumentException - Raised if provided value is lower than the allowed minimum.
    • estimate

      public double estimate() throws LockedException, NotReadyException
      Starts the estimation of the most likely value contained within provided input data array.
      Specified by:
      estimate in class MaximumLikelihoodEstimator
      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:
    • computeGaussian

      protected void computeGaussian(double[] gaussian, double centerPos)
      Internal method to compute values of Gaussian vector assumed to be centered at provided value. Gaussian values are stored in provided array so that array can be reused.
      Parameters:
      gaussian - Array containing Gaussian values
      centerPos - Value where Gaussian is centered
    • internalSetNumberOfBins

      private void internalSetNumberOfBins(int numberOfBins)
      Internal method to set number of bins to be used on the histogram. The larger the value being set the more precise results will be but more data will be needed to obtain statistically meaningful data so that enough samples are present on each bin.
      Parameters:
      numberOfBins - Number of bins to be used on the histogram.
      Throws:
      IllegalArgumentException - Raised if provided value is lower than the allowed minimum.