

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object org.opensha.commons.data.function.AbstractXY_DataSet org.opensha.commons.data.function.AbstractDiscretizedFunc org.opensha.commons.data.function.EvenlyDiscretizedFunc
public class EvenlyDiscretizedFunc
Title: EvenlyDiscretizedFunc
Description: Subclass of DiscretizedFunc and full implementation of DiscretizedFuncAPI. Assumes even spacing between the x points represented by the delta distance. Y Values are stored as doubles in an array of primitives. This allows replacement of values at specified indexes.
Note that the basic unit for this function framework are Point2D which contain x and y values. Since the xvalues are evenly space there are no need to store them. They can be calculated on the fly based on index. So the internal storage saves space by only saving the y values, and reconstituting the Point2D values as needed.
Since the x values are not stored, what is stored instead is the xmin value, xmax value, and the delta spacing between x values. This is enough to calculate any xvalue by index.
This function can be used to generate histograms. To do that, tolerance should be set greater than delta. Add methods should then be used to add to Y values for histograms. The x value is the midpoint of the histogram interval
Field Summary  

protected static String 
C
Class name used for debbuging 
protected static boolean 
D
if true print out debugging statements 
protected double 
delta
Distance between x points 
protected boolean 
first
Helper boolean that indicates no values have been put into this function yet. 
protected double 
maxX
The maximum xvalue in this series 
protected double 
minX
The minimum xvalue in this series, pins the index values with delta 
protected int 
num
Number of points in this function 
protected double[] 
points
The internal storage collection of points, stored as a linked list 
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  

EvenlyDiscretizedFunc(double min,
double max,
int num)
The other three input options to fully quantify the domain of this list, i.e. 

EvenlyDiscretizedFunc(double min,
int num,
double delta)
This is one of two constructor options to fully quantify the domain of this list, i.e. 
Method Summary  

void 
add(double x,
double y)
This method can be used for generating histograms if tolerance is set greater than delta. 
void 
add(int index,
double y)
This method can be used for generating histograms if tolerance is set greater than delta. 
boolean 
areAllXValuesInteger(double tolerance)
It finds out whether the X values are within tolerance of an integer value 
void 
clear()
Sets all y values to NaN 
EvenlyDiscretizedFunc 
deepClone()
Returns a copy of this and all points in this DiscretizedFunction. 
boolean 
equalXAndYValues(DiscretizedFunc function)
Determines if two functions are the same by comparing that each point x value is the same, within tolerance, and that each y value is the same, including nulls. 
boolean 
equalXValues(DiscretizedFunc function)
Determines if two functions are the same by comparing that each point x value is the same, within tolerance 
Point2D 
get(int index)
Returns an x and y value in a Point2D based on index into the ypoints array. 
int 
getClosestXIndex(double x)
Returns the index of the supplied value (ignoring tolerance). 
double 
getClosestYtoX(double x)
Get the Y value for the point with closest X. 
double 
getDelta()
Returns the spacing between xvalues 
int 
getIndex(Point2D point)
Returns the index of this DataPoint based on it's x any y value both the xvalue and yvalues in list should match with that of point returns 1 if there is no such value in the list 
double 
getMaxX()
Returns the maximum xvalue in this series. 
double 
getMaxY()
Returns the maximum yvalue in this series. 
String 
getMetadataString()
prints out the state of the list, such as number of points, the value of each point, etc. 
double 
getMinX()
Returns the minimum xvalue in this series. 
double 
getMinY()
Returns the minimum yvalue in this series. 
Iterator<Point2D> 
getPointsIterator()
This function may be slow if there are many points in the list. 
double 
getX(int index)
Returns the ith x element in this function. 
int 
getXIndex(double x)
Returns the index of the supplied value provided it's within the tolerance of one of the discretized values. 
protected int 
getXIndexBefore(double x)
Returns the x index that is before the given X value. 
int 
getXindexForMaxY()
Returns the x index for the maximum yvalue in this series. 
double 
getY(double x)
Returns theyvalue associated with this xvalue. 
double 
getY(int index)
Returns the ith y element in this function. 
void 
set(double x,
double y)
Sets the yvalue at a specified index. 
void 
set(double min,
double max,
int num)
Three input options to fully quantify the domain of this list, i.e. 
void 
set(double min,
int num,
double delta)
Fully quantify the domain of this list, i.e. 
void 
set(int index,
double y)
this function will throw an exception if the index is not within the range of 0 to num 1 
void 
set(Point2D point)
Calls set( x value, y value ). 
int 
size()
Returns the number of points in this series 
String 
toString()
Standard java function, usually used for debugging, prints out the state of the list, such as number of points, the value of each point, etc. 
protected boolean 
withinTolerance(double x,
double xx)
Returns true if two values are within tolerance to be considered equal. 
Methods inherited from class org.opensha.commons.data.function.AbstractDiscretizedFunc 

calcSumOfY_Vals, equals, fromXMLMetadata, getFirstInterpolatedX_inLogXLogYDomain, getFirstInterpolatedX, getInterpolatedY_inLogXLogYDomain, getInterpolatedY_inLogYDomain, getInterpolatedY, getTolerance, hasX, loadFuncFromSimpleFile, loadFuncFromSimpleFile, scale, setTolerance, toXMLMetadata, toXMLMetadata, writeSimpleFuncFile, writeSimpleFuncFile 
Methods inherited from class org.opensha.commons.data.function.AbstractXY_DataSet 

getClosestXtoY, getDatasetsToPlot, getInfo, getName, getPlotNumColorList, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, iterator, 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 

getClosestXtoY, 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 
Methods inherited from interface java.lang.Iterable 

iterator 
Field Detail 

protected static final String C
protected static final boolean D
protected double[] points
protected double minX
protected double maxX
protected double delta
protected int num
protected boolean first
Constructor Detail 

public EvenlyDiscretizedFunc(double min, int num, double delta)
min
  Starting x valuenum
  number of points in listdelta
  distance between x valuespublic EvenlyDiscretizedFunc(double min, double max, int num)
min
  Starting x valuenum
  number of points in listmax
  Ending x valueMethod Detail 

public void set(double min, int num, double delta)
min
  Starting x valuenum
  number of points in listdelta
  distance between x valuespublic void set(double min, double max, int num)
min
  Starting x valuenum
  number of points in listmax
  Ending x valuepublic void clear()
protected boolean withinTolerance(double x, double xx)
public double getDelta()
public int size()
public double getMinX()
public double getMaxX()
public double getMinY()
Note: An alternative would be to check for the min value every time a point is inserted and store the miny value. This would only slightly slow down the insert, but greatly speed up the lookup.
public double getMaxY()
Note: An alternative would be to check for the min value every time a point is inserted and store the miny value. This would only slightly slow down the insert, but greatly speed up the lookup.
public int getXindexForMaxY()
public Point2D get(int index)
public double getX(int index)
public double getY(int index)
public double getY(double x)
public int getXIndex(double x)
getClosestXIndex(double)
public int getClosestXIndex(double x)
public void set(Point2D point)
public void set(double x, double y)
public void add(double x, double y)
public void set(int index, double y)
public void add(int index, double y)
public Iterator<Point2D> getPointsIterator()
protected int getXIndexBefore(double x)
AbstractDiscretizedFunc
public double getClosestYtoX(double x)
XY_DataSet
getClosestYtoX
in interface XY_DataSet
getClosestYtoX
in class AbstractXY_DataSet
public EvenlyDiscretizedFunc deepClone()
This is a deep clone so all fields and all data points are copies.
public boolean equalXValues(DiscretizedFunc function)
public boolean areAllXValuesInteger(double tolerance)
areAllXValuesInteger
in interface XY_DataSet
areAllXValuesInteger
in class AbstractXY_DataSet
tol
 tolerance value to consider rounding errors
public boolean equalXAndYValues(DiscretizedFunc function)
public String toString()
toString
in interface XY_DataSet
toString
in class Object
public String getMetadataString()
XY_DataSet
public int getIndex(Point2D point)


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 