papaya
Class Frequency

java.lang.Object
  extended by papaya.Frequency

public class Frequency
extends Object

Class for getting the frequency distribution, cumulative frequency distribution, and other distribution-related parameters of a given array of floats or ints. To initialize, use something like this:

Frequency freq= new Frequency(dataArray, minimumVal,maximumVal,widthOfEachBin); Once initialized, it stores 3 things:

A number of different methods are available for computing other distribution-related parameters (e.g. the relative frequency distribution, the cumulative frequency distribution, etc).

See the FrequencyExample in the examples folder for an example.

Author:
Adila Faruk

Constructor Summary
Frequency(float[] _inputDat, float _minVal, float _maxVal, float _binWidth)
          Initialize the class by setting the minimum value, maximum value, and the bin width.
Frequency(int[] _inputDat, int _minVal, int _maxVal, int _binWidth)
          Initialize the class by setting the minimum value, maximum value, and the bin width.
 
Method Summary
 float[] compCumFrequency()
          Computes the cumulative frequency of the data.
 float[] compRelCumFrequency()
          Computes the cumulative relative frequency of the data.
 float[] compRelCumFrequencyPct()
          Computes the cumulative frequency of the data as a percentage.
 float[] compRelFrequency()
          Computes the fraction of the total data that's in each bin.
 float[] compRelFrequencyPct()
          Computes the percents of the total data that's in each bin.
 float[] getFrequency()
          Returns the pre-computed frequency array.
 int getLength()
          returns the length of the dataset.
 int getNumBins()
          Returns the number of bins.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Frequency

public Frequency(float[] _inputDat,
                 float _minVal,
                 float _maxVal,
                 float _binWidth)
Initialize the class by setting the minimum value, maximum value, and the bin width. Upon initialization, the number of bins are determined and the frequency distribution array is computed for the given input data and histogram bin width. This frequency distribution can be accessed using the getFrequency() function. Note that this is the only place where you can set the frequency distribution.

How is the number of bins computed?
Like this:
bins = floor[ (max - min) / binWidth ] +1 ,
as opposed to ceil[ (max - min) / binWidth ]. Why? The latter algorithm is problematic when [ (max - min) / binWidth ] is a whole number. E.g. let min = 0.0, max = 100.0, and binWidth = 10.0. We get 10 bins with

Poor 100. He's got nowhere to go but into an Array Index out of bound Exception!

What element goes into what bin?
Let value = data[i];
value will go into bin number floor( (_inputDat[i]-_minVal)/_binWidth );

Parameters:
_inputDat - the input data
_minVal - the minimum value in the array
_maxVal - the maximum value in the array
_binWidth - the width of each of the bins

Frequency

public Frequency(int[] _inputDat,
                 int _minVal,
                 int _maxVal,
                 int _binWidth)
Initialize the class by setting the minimum value, maximum value, and the bin width. Upon initialization, the number of bins are determined and the frequency distribution array is computed for the given input data and histogram bin width. This frequency distribution can be accessed using the getFrequency() function. Note that this is the only place where you can set the frequency distribution.

See Frequency(float[] _inputDat, float _minVal, float _maxVal, float _binWidth) for more details.

Method Detail

compRelFrequency

public float[] compRelFrequency()
Computes the fraction of the total data that's in each bin. This is similar to dividing the number in each bin by the total number of elements in the data array.


compRelFrequencyPct

public float[] compRelFrequencyPct()
Computes the percents of the total data that's in each bin. This isimilar to dividing the number in each bin by the total number of elements in the data array x 100%


compCumFrequency

public float[] compCumFrequency()
Computes the cumulative frequency of the data.


compRelCumFrequency

public float[] compRelCumFrequency()
Computes the cumulative relative frequency of the data. This is similar to dividing the number in each bin of the cumulative frequency array (compCumFrequency()) by the number of elements in the data array.


compRelCumFrequencyPct

public float[] compRelCumFrequencyPct()
Computes the cumulative frequency of the data as a percentage. This is similar to dividing the number in each bin of the cumulative frequency array (compCumFrequency()) by the number of elements in the data array x 100%.


getFrequency

public float[] getFrequency()
Returns the pre-computed frequency array. An array of floats so division won't cause any surprises.


getNumBins

public int getNumBins()
Returns the number of bins.


getLength

public int getLength()
returns the length of the dataset.



Processing library papaya by Adila Faruk. (C) 2014