Package adams.data.statistics
Class ArrayHistogram<T extends Number>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.statistics.AbstractArrayStatistic<T>
-
- adams.data.statistics.ArrayHistogram<T>
-
- 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ArrayHistogram.BinCalculation
Enumeration for the bin calculation.-
Nested classes/interfaces inherited from class adams.data.statistics.AbstractArrayStatistic
AbstractArrayStatistic.StatisticContainer<T extends Serializable>
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayHistogram.BinCalculation
m_BinCalculation
how to calculate the number of bins.protected double
m_BinWidth
the bin width - used for some calculations.protected boolean
m_DisplayRanges
whether to use the ranges as bin description.protected double
m_ManualMax
the manual maximum.protected double
m_ManualMin
the manual minimum.protected boolean
m_Normalize
whether to normalize the data.protected int
m_NumBins
the number of bins in case of manual bin calculation.protected int
m_NumDecimals
the number of decimals to show.protected boolean
m_UseFixedMinMax
whether to use fixed min/max for manual bin calculation.static String
METADATA_BINWIDTH
the key for the bin width in the meta-data.static String
METADATA_BINX
the key for the x-values for all the bins in the meta-data.static String
METADATA_MAXIMUM
the key for the maximum used in the meta-data.static String
METADATA_MINIMUM
the key for the minimum used in the meta-data.static String
METADATA_NUMBINS
the key for the number of bins in the meta-data.-
Fields inherited from class adams.data.statistics.AbstractArrayStatistic
m_Data
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description ArrayHistogram()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
binCalculationTipText()
Returns the tip text for this property.String
binWidthTipText()
Returns the tip text for this property.protected double[]
calcBinStarts(Number[] array, double width, int numBins, double min, double max)
Calculates the starting values for the bins.protected double
calcBinWidth(Number[] array)
Calculates the bin width to use.protected int
calcNumBins(Number[] array, double width)
Calculates the number of bins to use.void
defineOptions()
Adds options to the internal list of options.String
displayRangesTipText()
Returns the tip text for this property.protected AbstractArrayStatistic.StatisticContainer
doCalculate()
Generates the actual result.ArrayHistogram.BinCalculation
getBinCalculation()
Returns how the number of bins is calculated.double
getBinWidth()
Returns the bin width in use (for some calculations).boolean
getDisplayRanges()
Returns whether to use the bin ranges as their description rather than a simple index.int
getLength()
Returns the length of the stored arrays.double
getManualMax()
Returns the maximum to use when using manual binning with user-supplied max/max enabled.double
getManualMin()
Returns the minimum to use when using manual binning with user-supplied min/max enabled.int
getMax()
Returns the maximum number of arrays that need to be present.int
getMin()
Returns the minimum number of arrays that need to be present.boolean
getNormalize()
Returns whether to normalize the data before generating the histogram.int
getNumBins()
Returns the number of bins to use in manual calculation.int
getNumDecimals()
Returns the number of decimals to show in the bin description.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.boolean
getUseFixedMinMax()
Returns whether to use user-supplied min/max for bin calculation rather than obtain min/max from data.String
globalInfo()
Returns a string describing the object.String
manualMaxTipText()
Returns the tip text for this property.String
manualMinTipText()
Returns the tip text for this property.String
normalizeTipText()
Returns the tip text for this property.String
numBinsTipText()
Returns the tip text for this property.String
numDecimalsTipText()
Returns the tip text for this property.void
setBinCalculation(ArrayHistogram.BinCalculation value)
Sets how the number of bins is calculated.void
setBinWidth(double value)
Sets the bin width to use (for some calculations).void
setDisplayRanges(boolean value)
Sets whether to use the bin ranges as their description rather than a simple index.void
setManualMax(double value)
Sets the maximum to use when using manual binning with user-supplied max/max enabled.void
setManualMin(double value)
Sets the minimum to use when using manual binning with user-supplied min/max enabled.void
setNormalize(boolean value)
Sets whether to normalize the data before generating the histogram.void
setNumBins(int value)
Sets the number of bins to use in manual calculation.void
setNumDecimals(int value)
Sets the number of decimals to show in the bin description.void
setUseFixedMinMax(boolean value)
Sets whether to use user-supplied min/max for bin calculation rather than obtain min/max from data.String
useFixedMinMaxTipText()
Returns the tip text for this property.-
Methods inherited from class adams.data.statistics.AbstractArrayStatistic
add, calculate, check, checkEqualLength, clear, forCommandLine, forName, get, getAdditionalInformation, getStatistics, initialize, remove, set, shallowCopy, shallowCopy, size, toString
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
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_BinCalculation
protected ArrayHistogram.BinCalculation m_BinCalculation
how to calculate the number of bins.
-
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.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
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 interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractOptionHandler
-
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 interfaceEqualLengthArrayStatistic
- 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 classAbstractArrayStatistic<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 classAbstractArrayStatistic<T extends Number>
- Returns:
- the maximum number, -1 for unbounded
-
calcBinWidth
protected double calcBinWidth(Number[] array)
- 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 onwidth
- 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 onwidth
- the width of the binsnumBins
- the number of bins to usemin
- the minimum valuemax
- the maximum value- Returns:
- the starting values of the bins (+ one after)
-
doCalculate
protected AbstractArrayStatistic.StatisticContainer doCalculate()
Generates the actual result.- Specified by:
doCalculate
in classAbstractArrayStatistic<T extends Number>
- Returns:
- the generated result
-
-