

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. 
ArrayList<Double> 
getAllInterpolatedX(double y)
Given the input y value, finds all interpolated xaxis values where y equals the given value (using linear interpolation between neighboring points). 
int 
getClosestXIndex(double x)
Returns the index of the supplied value (ignoring tolerance). 
double 
getClosestY(double x)
Get the Y value for the point with closest X 
double 
getDelta()
Returns the spacing between xvalues 
double 
getFirstInterpolatedX_afterXindex(double y,
int xIndex)
Given the input y value, finds the two sequential x values with the closest y values, then calculates an interpolated x value for this y value, fitted to the curve. 
double 
getFirstInterpolatedX_inLogXLogYDomain(double y)
Given the input y value, finds the two sequential x values with the closest y values, then calculates an interpolated x value for this y value, fitted to the curve. 
double 
getFirstInterpolatedX(double y)
Given the input y value, finds the two sequential x values with the closest y values, then calculates an interpolated x value for this y value, fitted to the curve. 
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 
getInterpolatedY_inLogXLogYDomain(double x)
This function interpolates the yaxis value corresponding to the given value of x. 
double 
getInterpolatedY_inLogYDomain(double x)
This function interpolates the yaxis value corresponding to the given value of x. 
double 
getInterpolatedY(double x)
This function interpolates the yaxis value corresponding to the given value of x 
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. 
int 
getNum()
Returns the number of points 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. 
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. 
boolean 
hasPoint(double x,
double y)
Returns true if the x value is withing tolerance of an xvalue in this list, and the y value is equal to y value in the list. 
boolean 
hasPoint(Point2D point)
Returns true if the x value is withing tolerance of an xvalue in this list, and the y value is equal to y value in the list. 
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 ). 
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, getTolerance, loadFuncFromSimpleFile, loadFuncFromSimpleFile, scale, setTolerance, toXMLMetadata, toXMLMetadata, writeSimpleFuncFile, writeSimpleFuncFile 
Methods inherited from class org.opensha.commons.data.function.AbstractXY_DataSet 

getClosestX, 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 

getClosestX, 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 getNum()
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) throws Point2DException
Point2DException
getClosestXIndex(double)
public int getClosestXIndex(double x) throws Point2DException
Point2DException
public void set(Point2D point) throws Point2DException
Point2DException
public void set(double x, double y) throws Point2DException
Point2DException
public void add(double x, double y) throws Point2DException
Point2DException
public void set(int index, double y) throws Point2DException
Point2DException
public void add(int index, double y) throws Point2DException
Point2DException
public Iterator<Point2D> getPointsIterator()
public double getFirstInterpolatedX(double y)
Since there may be multiple y values with the same value, this function just matches the first found.
y(value
 for which interpolated first x value has to be found
public ArrayList<Double> getAllInterpolatedX(double y)
y(value
 for which interpolated first x value has to be found
public double getFirstInterpolatedX_afterXindex(double y, int xIndex)
Since there may be multiple y values with the same value, this function just matches the first found.
y(value
 for which interpolated first x value has to be found
public double getFirstInterpolatedX_inLogXLogYDomain(double y)
y
 : Y value in the linear space coressponding to which we are required to find the interpolated
x value in the log space.
public double getInterpolatedY(double x)
x(value
 for which interpolated first y value has to be found
public double getClosestY(double x)
XY_DataSet
getClosestY
in interface XY_DataSet
getClosestY
in class AbstractXY_DataSet
public double getInterpolatedY_inLogXLogYDomain(double x)
x
 : X value in the linear space corresponding to which we are required to find the interpolated
y value in log space.
public double getInterpolatedY_inLogYDomain(double x)
x
 : X value in the linear space corresponding to which we are required to find the interpolated
y value in log space.
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 boolean hasPoint(Point2D point)
public boolean hasPoint(double x, double y)
public int getIndex(Point2D point)


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