org.opensha.commons.data.function
Class ArbDiscrEmpiricalDistFunc

java.lang.Object
  extended by org.opensha.commons.data.function.AbstractXY_DataSet
      extended by org.opensha.commons.data.function.AbstractDiscretizedFunc
          extended by org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc
              extended by org.opensha.commons.data.function.ArbDiscrEmpiricalDistFunc
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<java.awt.geom.Point2D>, DiscretizedFunc, XY_DataSet, Named, PlotElement, XMLSaveable

public class ArbDiscrEmpiricalDistFunc
extends ArbitrarilyDiscretizedFunc
implements java.io.Serializable

Title: ArbDiscrEmpiricalDistFunc

Description: This class is similar to ArbitraryDiscretizedFunction, except that rather than replacing a point that has the same x value (or within tolerance, which is required to be near zero here), the y values are added together. This is useful for making an empirical distribution where the y-values represent the frequency of occurrence of each x value. In this context, a nonzero tolerance would not make sense because a values might fall into different points depending on what order they're added. Due to the numerical precision of floating point arithmetic, the tolerance is really about 1e-16 (multiple values within this tolerance will be added together).

The getNormalizedCumDist() method enables one to get a normalized cumulative distribution.

The getFractile(fraction) method gets the x-axis value for the specified fraction (does so by creating a NormalizedCumDist each time, so this is not efficient if several fractiles are desired).

Version:
1.0
Author:
Edward H. Field
See Also:
Serialized Form

Field Summary
protected static java.lang.String C
           
protected static boolean D
           
 
Fields inherited from class org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc
points
 
Fields inherited from class org.opensha.commons.data.function.AbstractDiscretizedFunc
tolerance, XML_METADATA_NAME, XML_METADATA_POINT_NAME, XML_METADATA_POINTS_NAME
 
Fields inherited from class org.opensha.commons.data.function.AbstractXY_DataSet
info, name, xAxisName, yAxisName
 
Constructor Summary
ArbDiscrEmpiricalDistFunc()
          No-Arg Constructor.
 
Method Summary
 ArbDiscrEmpiricalDistFunc deepClone()
          This function returns a new copy of this list, including copies of all the points.
 double getCOV()
          This returns the coefficient of variation (standard deviation divided by the mean)
 ArbitrarilyDiscretizedFunc getCumDist()
          This returns an ArbitrarilyDiscretizedFunc representing the cumulative distribution (sum of Y values less than and equal te each X value).
 double getDiscreteFractile(double fraction)
          This returns the greatest uninterpolated x-axis value whose normalized cumulative distribution value is less than or equal to fraction.
 double getInterpolatedFractile(double fraction)
          This returns the x-axis value where the interpolated normalized cumulative distribution equals the specified fraction.
 double getMean()
          calculates the mean for normalized distribution (done simply as a weight average)
 double getMedian()
          Get the median.
 double getMode()
          Get the mode (X value where Y is maximum).
 double getMostCentralMode()
          Get the most central mode in the case of a multi-modal distribution.
 ArbitrarilyDiscretizedFunc getNormalizedCumDist()
          This returns an ArbitrarilyDiscretizedFunc representing the cumulative distribution normalized (so that the last value is equal to one)
 double getStdDev()
          Calculates the standard deviation for normalized distribution
 double getSumOfAllY_Values()
          This returns the sum of all Y values
 boolean isMultiModal()
           
static void main(java.lang.String[] args)
           
 void setTolerance(double newTolerance)
          This method is over ridded to throw an exception because tolerance cannot be changed from zero for this class.
 
Methods inherited from class org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc
clear, equalXValues, get, getFirstInterpolatedX_inLogXLogYDomain, getFirstInterpolatedX, getIndex, getInterpExterpY_inLogYDomain, getInterpolatedY_inLogXLogYDomain, getInterpolatedY_inLogYDomain, getInterpolatedY, getMaxX, getMaxY, getMetadataString, getMinX, getMinY, getNum, getPointsIterator, getX, getXIndex, getXVals, getY, getY, getYVals, getYY_Function, hasPoint, hasPoint, iterator, set, set, set, toDebugString, toString
 
Methods inherited from class org.opensha.commons.data.function.AbstractDiscretizedFunc
calcSumOfY_Vals, equals, fromXMLMetadata, getTolerance, loadFuncFromSimpleFile, loadFuncFromSimpleFile, scale, toXMLMetadata, toXMLMetadata, writeSimpleFuncFile, writeSimpleFuncFile
 
Methods inherited from class org.opensha.commons.data.function.AbstractXY_DataSet
areAllXValuesInteger, getClosestX, getClosestY, getDatasetsToPlot, getInfo, getName, getPlotNumColorList, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, setInfo, setName, setXAxisName, setYAxisName, xValues, yValues
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opensha.commons.data.function.XY_DataSet
areAllXValuesInteger, getClosestX, getClosestY, getInfo, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, setInfo, setName, setXAxisName, setYAxisName, xValues, yValues
 
Methods inherited from interface org.opensha.commons.gui.plot.PlotElement
getDatasetsToPlot, getPlotNumColorList
 
Methods inherited from interface org.opensha.commons.data.Named
getName
 

Field Detail

C

protected static final java.lang.String C
See Also:
Constant Field Values

D

protected static final boolean D
See Also:
Constant Field Values
Constructor Detail

ArbDiscrEmpiricalDistFunc

public ArbDiscrEmpiricalDistFunc()
No-Arg Constructor.

Method Detail

setTolerance

public void setTolerance(double newTolerance)
                  throws InvalidRangeException
This method is over ridded to throw an exception because tolerance cannot be changed from zero for this class.

Specified by:
setTolerance in interface DiscretizedFunc
Overrides:
setTolerance in class ArbitrarilyDiscretizedFunc
Throws:
InvalidRangeException

deepClone

public ArbDiscrEmpiricalDistFunc deepClone()
This function returns a new copy of this list, including copies of all the points. A shallow clone would only create a new DiscretizedFunc instance, but would maintain a reference to the original points.

Since this is a clone, you can modify it without changing the original.

Specified by:
deepClone in interface DiscretizedFunc
Specified by:
deepClone in interface XY_DataSet
Overrides:
deepClone in class ArbitrarilyDiscretizedFunc
Returns:

getInterpolatedFractile

public double getInterpolatedFractile(double fraction)
This returns the x-axis value where the interpolated normalized cumulative distribution equals the specified fraction. If the fraction is below the Y- value of the first point, then the X value of the first point is returned (since there is nothing below to interpolate with)

Parameters:
fraction - - a value between 0 and 1.
Returns:

getDiscreteFractile

public double getDiscreteFractile(double fraction)
This returns the greatest uninterpolated x-axis value whose normalized cumulative distribution value is less than or equal to fraction. distribution.

Parameters:
fraction - - a value between 0 and 1.
Returns:

getNormalizedCumDist

public ArbitrarilyDiscretizedFunc getNormalizedCumDist()
This returns an ArbitrarilyDiscretizedFunc representing the cumulative distribution normalized (so that the last value is equal to one)

Returns:

getSumOfAllY_Values

public double getSumOfAllY_Values()
This returns the sum of all Y values

Returns:

getMean

public double getMean()
calculates the mean for normalized distribution (done simply as a weight average)

Returns:

getStdDev

public double getStdDev()
Calculates the standard deviation for normalized distribution

Returns:

getCOV

public double getCOV()
This returns the coefficient of variation (standard deviation divided by the mean)

Returns:

getMode

public double getMode()
Get the mode (X value where Y is maximum). Returns throws a runtime exception in the case of a multi-modal distribution

Returns:

getMostCentralMode

public double getMostCentralMode()
Get the most central mode in the case of a multi-modal distribution. If there is an even number of modes (two central modes) we give back the larger of the two.

Returns:

isMultiModal

public boolean isMultiModal()

getMedian

public double getMedian()
Get the median. It returns the interpolated fractile at 0.5 for normalized distribution.

Returns:

getCumDist

public ArbitrarilyDiscretizedFunc getCumDist()
This returns an ArbitrarilyDiscretizedFunc representing the cumulative distribution (sum of Y values less than and equal te each X value).

Returns:

main

public static void main(java.lang.String[] args)