Package pamMaths

Class PamHistogram

All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
CalibrationHistogram, PamLogHistogram, TriggerHistogram

public class PamHistogram extends TimedObservable implements Cloneable
class for collecting data into a 1-D histogram.

As well as basic histogramming functions, functions exist for downscaling the histogram data and extracting parameters such as variance, skew, etc.

Author:
Doug Gillespie
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    PamHistogram(double minVal, double maxVal, int nBins)
    Constructs a histogram object with minVal and maxVal, specifying the low edge of the lowest bin and the high edge of the highest bin respectively.
    PamHistogram(double minVal, double maxVal, int nBins, boolean binCentres)
    Constructs a histogram object where minVal and maxVal specify the centres of the lower and upper bins (true) or the lower edge of the lowest bin and the upper edge of the highest bin (false)
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    addData(double newData)
    Add a single point of data to the histogram but don't notify observers
    void
    addData(double newData, boolean notify)
    Add a single unit value to the histogram and optionally notify all observers
    void
    addData(double newData, double weight)
    Add weighted data to the histogram
    void
    Clear all histogram contents
    int
    getBin(double dataValue)
    Work out which bin a particular value will call into.
    double
    getBinCentre(int iBin)
     
    double[]
    Get the centre value of every bin
    double[]
    Get an array of bin edges.
    double[]
    Get the histograms data array.
    double
    Get content of high bin - values > max range of histogram
    double
    Get the kurtosis of the distribution (fourth moment) taking the definition from Numerical recipes in C p 612
    double
    Get content of low bin - values invalid input: '<' min range of histogram
    double
    Get max bin content, including lo and high fields.
    double
    Get the maximum range value of the histogram
    double
    Calculate the mean of the histogram data
    double
    Get the minimum range value of the histogram
    double
    Get's the modal value of the distribution
     
    int
    Get the number of histogram bins
    double
    Where to plot to if bin centres were specified.
    double
    Where to plot from if bin centres were specified.
    double
    Get the skewness of the distribution (third moment)
    double
    Return the standard deviation of the histogram data
    double
    Step size between sucessive bins.
    double
    Get's the sum total of all bin contents, excluding lo and high bins
    double
    Return the variance of the histogram data
    boolean
     
    void
     
    void
    printSummary(String title, PrintStream printStream)
     
    void
    scaleData(double scaleFactor)
    Scale the data in the histogram by the given factor
    void
    setBinCentres(boolean binCentres)
     
    void
    setData(int[] data)
    Set the histogram data
    void
     
    void
    setRange(double minVal, double maxVal, int nBins)
    Sets the histogram bin ranges.
     

    Methods inherited from class java.util.Observable Link icon

    addObserver, countObservers, deleteObserver, deleteObservers, hasChanged

    Methods inherited from class java.lang.Object Link icon

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details Link icon

    • PamHistogram Link icon

      public PamHistogram(double minVal, double maxVal, int nBins)
      Constructs a histogram object with minVal and maxVal, specifying the low edge of the lowest bin and the high edge of the highest bin respectively.
      Parameters:
      minVal - min Value
      maxVal - max Value
      nBins - number of bins
    • PamHistogram Link icon

      public PamHistogram(double minVal, double maxVal, int nBins, boolean binCentres)
      Constructs a histogram object where minVal and maxVal specify the centres of the lower and upper bins (true) or the lower edge of the lowest bin and the upper edge of the highest bin (false)
      Parameters:
      minVal - minimum value (low edge or low bin centre, depending on binCentres parameter)
      maxVal - maximum value (high edge or high bin centre, depending on binCentres parameter)
      nBins - total number of bins
      binCentres - specifies whether the minVal and maxVal specify the centres of the lower and upper bins (true) or the lower edge of the lowest bin and the upper edge of the highest bin (false)
  • Method Details Link icon

    • setRange Link icon

      public void setRange(double minVal, double maxVal, int nBins)
      Sets the histogram bin ranges.

      Note that calling this function will reset the histogram data.

      Parameters:
      minVal - minimum value (low edge or low bin centre, depending on binCentres parameter)
      maxVal - maximum value (high edge or high bin centre, depending on binCentres parameter)
      nBins - total number of bins
    • getBin Link icon

      public int getBin(double dataValue)
      Work out which bin a particular value will call into. N.B. This may return invalid input: '<' 0 or >= getNBins() if the data fall outsied the range of the histogram
      Parameters:
      dataValue -
      Returns:
      bin Bumber
    • getBinCentre Link icon

      public double getBinCentre(int iBin)
    • setData Link icon

      public void setData(int[] data)
      Set the histogram data
      Parameters:
      data - array must be same length as data array in histogram.
    • addData Link icon

      public void addData(double newData, boolean notify)
      Add a single unit value to the histogram and optionally notify all observers
      Parameters:
      newData - value of the new data
    • addData Link icon

      public void addData(double newData)
      Add a single point of data to the histogram but don't notify observers
      Parameters:
      newData - new data point
    • addData Link icon

      public void addData(double newData, double weight)
      Add weighted data to the histogram
      Parameters:
      newData - value of the data
      weight - weight to apply
    • clear Link icon

      public void clear()
      Clear all histogram contents
    • scaleData Link icon

      public void scaleData(double scaleFactor)
      Scale the data in the histogram by the given factor

      This is used in various parts of PAMGUARD which wish to keep a decaying average distribution - every few seconds the data are halved (or some such) so that all data are represented, but recent data will carry more weight in the distributions.

      Parameters:
      scaleFactor - FActor to scale data by (generally invalid input: '<' 1)
    • getMaxContent Link icon

      public double getMaxContent()
      Get max bin content, including lo and high fields.
      Returns:
      max bin content.
    • getMean Link icon

      public double getMean()
      Calculate the mean of the histogram data
      Returns:
      mean value
    • getSTD Link icon

      public double getSTD()
      Return the standard deviation of the histogram data
      Returns:
      standard deviation
    • getVariance Link icon

      public double getVariance()
      Return the variance of the histogram data
      Returns:
      get variance of distribution in histogram
    • getSkew Link icon

      public double getSkew()
      Get the skewness of the distribution (third moment)
      Returns:
      skew
    • getKurtosis Link icon

      public double getKurtosis()
      Get the kurtosis of the distribution (fourth moment) taking the definition from Numerical recipes in C p 612
      Returns:
      kurtosis
    • getMode Link icon

      public double getMode()
      Get's the modal value of the distribution
      Returns:
      value of the bin centre for the most populated bin
    • getTotalContent Link icon

      public double getTotalContent()
      Get's the sum total of all bin contents, excluding lo and high bins
      Returns:
      get total content of all histogram bins
    • getData Link icon

      public double[] getData()
      Get the histograms data array.
      Returns:
      An array of double data
    • getMaxVal Link icon

      public double getMaxVal()
      Get the maximum range value of the histogram
      Returns:
      max value
    • getMinVal Link icon

      public double getMinVal()
      Get the minimum range value of the histogram
      Returns:
      min value
    • getScaleMinVal Link icon

      public double getScaleMinVal()
      Where to plot from if bin centres were specified.
      Returns:
      minimum value for plot axis
    • getScaleMaxVal Link icon

      public double getScaleMaxVal()
      Where to plot to if bin centres were specified.
      Returns:
      maximum value for plot axis
    • getNBins Link icon

      public int getNBins()
      Get the number of histogram bins
      Returns:
      number of histogram bins
    • getStep Link icon

      public double getStep()
      Step size between sucessive bins.
      Returns:
      histogram step size (bin width)
    • getName Link icon

      public String getName()
    • setName Link icon

      public void setName(String name)
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • getHiBin Link icon

      public double getHiBin()
      Get content of high bin - values > max range of histogram
      Returns:
      high bin content
    • getLoBin Link icon

      public double getLoBin()
      Get content of low bin - values invalid input: '<' min range of histogram
      Returns:
      low bin content
    • isBinCentres Link icon

      public boolean isBinCentres()
    • setBinCentres Link icon

      public void setBinCentres(boolean binCentres)
    • getBinCentreValues Link icon

      public double[] getBinCentreValues()
      Get the centre value of every bin
      Returns:
      array of bin centres.
    • getBinEdgeValues Link icon

      public double[] getBinEdgeValues()
      Get an array of bin edges. This will be one longer than the number of bins
      Returns:
      array of bin edge values.
    • printSummary Link icon

      public void printSummary()
    • printSummary Link icon

      public void printSummary(String title, PrintStream printStream)