public class ArbitrarilyDiscretizedFunc extends AbstractDiscretizedFunc
Description: This class is a sublcass implementation of a DiscretizedFunc that stores the data internaly as a sorted TreeMap of DataPoint2D. This subclass distinguishes itself by the fact that it assumes no spacing interval along the x-axis. Consecutive points can be spread out or bunched up in no predicatable order. For at least the default comparator (DataPoint2DComparator), the tolerance determines whether the set() methods add the point (if x value is more than tolerance away from that of all existing points) or whether they replace an existing point (if within tolerance). A tolerance of less than about 1e-16 is effectively about 1e-16 due to the numerical precision of floating point arithmetic (1.0 - (1.0+1e-16) = 1.0).
| Modifier and Type | Field and Description |
|---|---|
protected Point2DToleranceSortedList |
points
The set of DataPoints2D that conprise the discretized function.
|
C, D, toleranceinfo, name, xAxisName, yAxisName| Constructor and Description |
|---|
ArbitrarilyDiscretizedFunc()
No-Arg Constructor that uses the default DataPoint2DToleranceComparator
comparator.
|
ArbitrarilyDiscretizedFunc(AbstractDiscretizedFunc func)
Creates an ArbitrarilyDiscretizedFunc from an DiscretizedFunc
|
ArbitrarilyDiscretizedFunc(Point2DComparator comparator)
Constructor that takes a Point2D Comparator.
|
ArbitrarilyDiscretizedFunc(Point2DToleranceSortedList points) |
ArbitrarilyDiscretizedFunc(String name)
Creates a default arbitrarily discretized function with the given name
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear all the X and Y values from this function
|
ArbitrarilyDiscretizedFunc |
deepClone()
This function returns a new copy of this list, including copies of all the
points.
|
boolean |
equalXValues(DiscretizedFunc function)
Determines if two functions are the same by comparing that each point x
value is the same.
|
Point2D |
get(int index)
Returns the nth (x,y) point in the Function, else null if this index point
doesn't exist
|
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 imput 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 Y value given an x value - within tolerance, returns null if
not found
|
double |
getInterpExterpY_inLogYDomain(double x) |
double |
getInterpolatedY_inLogXLogYDomain(double x)
This function interpolates the y-axis value corresponding to the given
value of x.
|
double |
getInterpolatedY_inLogYDomain(double x)
This function interpolates the y-axis value corresponding to the given
value of x.
|
double |
getInterpolatedY(double x)
Given the imput x value, finds the two sequential x values with the closest
x values, then calculates an interpolated y value for this x value, fitted
to the curve.
|
double |
getMaxX()
return the maximum x value along the x-axis.
|
double |
getMaxY()
Return the maximum y value along the y-axis.
|
String |
getMetadataString()
prints out the state of the list, such as number of points, the value of
each point, etc.
|
double |
getMinX()
return the minimum x value along the x-axis.
|
double |
getMinY()
Return the minimum y value along the y-axis.
|
int |
getNum()
returns the number of points in this function list
|
Iterator<Point2D> |
getPointsIterator()
Returns an iterator over all datapoints in the list.
|
double |
getX(int index)
Returns the x value of a point given the index
|
int |
getXIndex(double x)
Returns the x value of a point given the index or -1 if not found
|
double[] |
getXVals() |
double |
getY(double x)
returns the Y value given an x value - within tolerance, returns null if
not found
|
double |
getY(int index)
Returns the y value of a point given the index
|
double[] |
getYVals() |
ArbitrarilyDiscretizedFunc |
getYY_Function(DiscretizedFunc function)
This function creates a new ArbitrarilyDiscretizedFunc whose X values are
the Y values of the calling function and Y values are the Y values of the
function passed as argument.
|
boolean |
hasPoint(double x,
double y)
Determinces if a DataPoit2D exists in the treemap base on it's x value
lookup.
|
boolean |
hasPoint(Point2D point)
Determinces if a DataPoit2D exists in the treemap base on it's x value
lookup.
|
Iterator<Point2D> |
iterator() |
static void |
main(String[] args) |
void |
set(double x,
double y)
Either adds a new DataPoint, or replaces an existing one, within tolerance,
created from the input x and y values.
|
void |
set(int index,
double y)
Replaces a y value for an existing point, accessed by index.
|
void |
set(Point2D point)
Either adds a new DataPoint, or replaces an existing one, within tolerance
|
void |
setTolerance(double newTolerance)
Sets the tolerance of this function.
|
String |
toDebugString()
Almost the same as toString() but used specifically in a debugging context.
|
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.
|
calcSumOfY_Vals, equals, getTolerance, scaleareAllXValuesInteger, getClosestX, getClosestY, getInfo, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, name, setInfo, setName, setXAxisName, setYAxisName, xValues, yValuesclone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitareAllXValuesInteger, getClosestX, getClosestY, getInfo, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, setInfo, setName, setXAxisName, setYAxisName, xValues, yValuesforEach, spliteratorprotected Point2DToleranceSortedList points
This TreeMap will not allow identical DataPoint2D. A comparator and equals() is used to determine equality. Since you can specify any comparator you want, this ArbitrarilyDiscretizedFunc can be adopted for most purposes.
Note: SWR: I had to make a special org.opensha. version of the Java TreeMap and subclass DataPoint2DTreeMap to access internal objects in the Java TreeMap. Java's Treemap had internal objects hidden as private, I exposed them to subclasses by making them protected in org.opensha.data.TreeMap. This was neccessary for index access to the points in the TreeMap. Seems like a poor oversight on the part of Java.
public ArbitrarilyDiscretizedFunc(AbstractDiscretizedFunc func)
func - public ArbitrarilyDiscretizedFunc(Point2DComparator comparator)
The passed in comparator must be an implementor of DataPoint2DComparatorAPI. These comparators know they are dealing with a Point2D and usually only compare the x-values for sorting. Special comparators may wish to sort on both the x and y values, i.e. the data points are geographical locations.
public ArbitrarilyDiscretizedFunc()
The default tolerance of 0 is used. This means that two x-values must be exactly equal doubles to be considered equal.
public ArbitrarilyDiscretizedFunc(String name)
name - public ArbitrarilyDiscretizedFunc(Point2DToleranceSortedList points)
public void setTolerance(double newTolerance)
setTolerance in interface DiscretizedFuncsetTolerance in class AbstractDiscretizedFuncpublic int getNum()
public double getMinX()
public double getMaxX()
public double getMinY()
public double getMaxY()
public Point2D get(int index)
public double getX(int index)
public double getY(int index)
public double getY(double x)
public int getIndex(Point2D point)
public int getXIndex(double x)
public void set(Point2D point)
public void set(double x,
double y)
public void set(int index,
double y)
public boolean hasPoint(Point2D point)
public boolean hasPoint(double x,
double y)
public Iterator<Point2D> getPointsIterator()
public Iterator<Point2D> iterator()
iterator in interface Iterable<Point2D>iterator in class AbstractXY_DataSetpublic 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 foundpublic 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 foundpublic 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 double getInterpExterpY_inLogYDomain(double x)
public ArbitrarilyDiscretizedFunc deepClone()
Since this is a clone, you can modify it without changing the original.
public boolean equalXValues(DiscretizedFunc function)
public String toString()
toString in interface XY_DataSettoString in class Objectpublic String getMetadataString()
XY_DataSetpublic String toDebugString()
public ArbitrarilyDiscretizedFunc getYY_Function(DiscretizedFunc function)
function - DiscretizedFuncAPI function whose Y values will the Y
values of the new ArbitrarilyDiscretizedFunc.public void clear()
public double[] getXVals()
public double[] getYVals()
public static void main(String[] args)