Class ArrayHistogram<T extends Number>

  • Type Parameters:
    T - the data to process
    All Implemented Interfaces:
    AdditionalInformationHandler, Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, ShallowCopySupporter<AbstractArrayStatistic>, SizeOfHandler, TechnicalInformationHandler, EqualLengthArrayStatistic, Serializable

    public class ArrayHistogram<T extends Number>
    extends AbstractArrayStatistic<T>
    implements EqualLengthArrayStatistic, TechnicalInformationHandler
    Generates a histogram from the given array.
    The formulas for the various width/#bin calculations can be found here:
    WikiPedia (2010). Histogram.

     @misc{WikiPedia2010,
        author = {WikiPedia},
        title = {Histogram},
        year = {2010},
        HTTP = {http://en.wikipedia.org/wiki/Histogram}
     }
     


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -bin-calc <MANUAL|FREQUENCY|DENSITY|STURGES|SCOTT|SQRT> (property: binCalculation)
        Defines how the number of bins are calculated.
        default: MANUAL
     
    -num-bins <int> (property: numBins)
        The number of bins to use in case of manual bin calculation.
        default: 50
        minimum: 1
     
    -bin-width <double> (property: binWidth)
        The bin width to use for some of the calculations.
        default: 1.0
        minimum: 1.0E-5
     
    -normalize <boolean> (property: normalize)
        If set to true the data gets normalized first before the histogram is calculated.
        default: false
     
    -use-fixed-min-max <boolean> (property: useFixedMinMax)
        If enabled, then the user-specified min/max values are used for the bin 
        calculation rather than the min/max from the data (allows comparison of 
        histograms when generating histograms over a range of arrays).
        default: false
     
    -manual-min <double> (property: manualMin)
        The minimum to use when using manual binning with user-supplied min/max 
        enabled.
        default: 0.0
     
    -manual-max <double> (property: manualMax)
        The maximum to use when using manual binning with user-supplied max/max 
        enabled.
        default: 1.0
     
    -display-ranges <boolean> (property: displayRanges)
        If enabled, the bins get description according to their range, rather than 
        a simple index.
        default: false
     
    -num-decimals <int> (property: numDecimals)
        The number of decimals to show in the bin descriptions.
        default: 3
        minimum: 0
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • METADATA_NUMBINS

        public static final String METADATA_NUMBINS
        the key for the number of bins in the meta-data.
        See Also:
        Constant Field Values
      • METADATA_BINWIDTH

        public static final String METADATA_BINWIDTH
        the key for the bin width in the meta-data.
        See Also:
        Constant Field Values
      • METADATA_BINX

        public static final String METADATA_BINX
        the key for the x-values for all the bins in the meta-data.
        See Also:
        Constant Field Values
      • METADATA_MINIMUM

        public static final String METADATA_MINIMUM
        the key for the minimum used in the meta-data.
        See Also:
        Constant Field Values
      • METADATA_MAXIMUM

        public static final String METADATA_MAXIMUM
        the key for the maximum used in the meta-data.
        See Also:
        Constant Field Values
      • m_NumBins

        protected int m_NumBins
        the number of bins in case of manual bin calculation.
      • m_BinWidth

        protected double m_BinWidth
        the bin width - used for some calculations.
      • m_Normalize

        protected boolean m_Normalize
        whether to normalize the data.
      • m_UseFixedMinMax

        protected boolean m_UseFixedMinMax
        whether to use fixed min/max for manual bin calculation.
      • m_ManualMin

        protected double m_ManualMin
        the manual minimum.
      • m_ManualMax

        protected double m_ManualMax
        the manual maximum.
      • m_DisplayRanges

        protected boolean m_DisplayRanges
        whether to use the ranges as bin description.
      • m_NumDecimals

        protected int m_NumDecimals
        the number of decimals to show.
    • Constructor Detail

      • ArrayHistogram

        public ArrayHistogram()
    • Method Detail

      • getTechnicalInformation

        public TechnicalInformation getTechnicalInformation()
        Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
        Specified by:
        getTechnicalInformation in interface TechnicalInformationHandler
        Returns:
        the technical information about this class
      • setBinCalculation

        public void setBinCalculation​(ArrayHistogram.BinCalculation value)
        Sets how the number of bins is calculated.
        Parameters:
        value - the bin calculation
      • getBinCalculation

        public ArrayHistogram.BinCalculation getBinCalculation()
        Returns how the number of bins is calculated.
        Returns:
        the bin calculation
      • binCalculationTipText

        public String binCalculationTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNumBins

        public void setNumBins​(int value)
        Sets the number of bins to use in manual calculation.
        Parameters:
        value - the number of bins
      • getNumBins

        public int getNumBins()
        Returns the number of bins to use in manual calculation.
        Returns:
        the number of bins
      • numBinsTipText

        public String numBinsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setBinWidth

        public void setBinWidth​(double value)
        Sets the bin width to use (for some calculations).
        Parameters:
        value - the bin width
      • getBinWidth

        public double getBinWidth()
        Returns the bin width in use (for some calculations).
        Returns:
        the bin width
      • binWidthTipText

        public String binWidthTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNormalize

        public void setNormalize​(boolean value)
        Sets whether to normalize the data before generating the histogram.
        Parameters:
        value - if true the data gets normalized first
      • getNormalize

        public boolean getNormalize()
        Returns whether to normalize the data before generating the histogram.
        Returns:
        true if the data gets normalized first
      • normalizeTipText

        public String normalizeTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setUseFixedMinMax

        public void setUseFixedMinMax​(boolean value)
        Sets whether to use user-supplied min/max for bin calculation rather than obtain min/max from data.
        Parameters:
        value - true if to use user-supplied min/max
      • getUseFixedMinMax

        public boolean getUseFixedMinMax()
        Returns whether to use user-supplied min/max for bin calculation rather than obtain min/max from data.
        Returns:
        true if to use user-supplied min/max
      • useFixedMinMaxTipText

        public String useFixedMinMaxTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setManualMin

        public void setManualMin​(double value)
        Sets the minimum to use when using manual binning with user-supplied min/max enabled.
        Parameters:
        value - the minimum
      • getManualMin

        public double getManualMin()
        Returns the minimum to use when using manual binning with user-supplied min/max enabled.
        Returns:
        the minimum
      • manualMinTipText

        public String manualMinTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setManualMax

        public void setManualMax​(double value)
        Sets the maximum to use when using manual binning with user-supplied max/max enabled.
        Parameters:
        value - the maximum
      • getManualMax

        public double getManualMax()
        Returns the maximum to use when using manual binning with user-supplied max/max enabled.
        Returns:
        the maximum
      • manualMaxTipText

        public String manualMaxTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setDisplayRanges

        public void setDisplayRanges​(boolean value)
        Sets whether to use the bin ranges as their description rather than a simple index.
        Parameters:
        value - true if to display the ranges
      • getDisplayRanges

        public boolean getDisplayRanges()
        Returns whether to use the bin ranges as their description rather than a simple index.
        Returns:
        true if to display the ranges
      • displayRangesTipText

        public String displayRangesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setNumDecimals

        public void setNumDecimals​(int value)
        Sets the number of decimals to show in the bin description.
        Parameters:
        value - the number of decimals
      • getNumDecimals

        public int getNumDecimals()
        Returns the number of decimals to show in the bin description.
        Returns:
        the number of decimals
      • numDecimalsTipText

        public String numDecimalsTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getLength

        public int getLength()
        Returns the length of the stored arrays.
        Specified by:
        getLength in interface EqualLengthArrayStatistic
        Returns:
        the length of the arrays, -1 if none stored
      • getMin

        public int getMin()
        Returns the minimum number of arrays that need to be present. -1 for unbounded.
        Specified by:
        getMin in class AbstractArrayStatistic<T extends Number>
        Returns:
        the minimum number, -1 for unbounded
      • getMax

        public int getMax()
        Returns the maximum number of arrays that need to be present. -1 for unbounded.
        Specified by:
        getMax in class AbstractArrayStatistic<T extends Number>
        Returns:
        the maximum number, -1 for unbounded
      • calcBinWidth

        protected double calcBinWidth​(Number[] array)
        Calculates the bin width to use.

        Formulas taken from here:
        Parameters:
        array - the array to work on
        Returns:
        the width of the bins, -1 if not necessary
      • calcNumBins

        protected int calcNumBins​(Number[] array,
                                  double width)
        Calculates the number of bins to use.

        Formulas taken from here:
        Parameters:
        array - the array to work on
        width - the width of the bins
        Returns:
        the number of bins to use
      • calcBinStarts

        protected double[] calcBinStarts​(Number[] array,
                                         double width,
                                         int numBins,
                                         double min,
                                         double max)
        Calculates the starting values for the bins.
        Parameters:
        array - the array to work on
        width - the width of the bins
        numBins - the number of bins to use
        min - the minimum value
        max - the maximum value
        Returns:
        the starting values of the bins (+ one after)