|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opensha.commons.data.function.AbstractXY_DataSet
org.opensha.commons.data.function.AbstractDiscretizedFunc
org.opensha.commons.data.function.ArbitrarilyDiscretizedFunc
public class ArbitrarilyDiscretizedFunc
Title: ArbitrarilyDiscretizedFunc
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).
| Field Summary | |
|---|---|
protected static String |
C
|
protected static boolean |
D
|
protected Point2DToleranceSortedList |
points
The set of DataPoints2D that conprise the discretized function. |
| 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 | |
|---|---|
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 |
|
| Method Summary | |
|---|---|
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. |
| 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 |
|---|
protected static final String C
protected static final boolean D
protected 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.
| Constructor Detail |
|---|
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)
| Method Detail |
|---|
public void setTolerance(double newTolerance)
throws InvalidRangeException
setTolerance in interface DiscretizedFuncsetTolerance in class AbstractDiscretizedFuncInvalidRangeExceptionpublic int getNum()
getNum in interface XY_DataSetpublic double getMinX()
getMinX in interface XY_DataSetpublic double getMaxX()
getMaxX in interface XY_DataSetpublic double getMinY()
getMinY in interface XY_DataSetpublic double getMaxY()
getMaxY in interface XY_DataSetpublic Point2D get(int index)
get in interface XY_DataSetpublic double getX(int index)
getX in interface XY_DataSetpublic double getY(int index)
getY in interface XY_DataSetpublic double getY(double x)
getY in interface DiscretizedFuncpublic int getIndex(Point2D point)
getIndex in interface DiscretizedFuncpublic int getXIndex(double x)
getXIndex in interface DiscretizedFunc
public void set(Point2D point)
throws Point2DException
set in interface XY_DataSetPoint2DException
public void set(double x,
double y)
throws Point2DException
set in interface XY_DataSetPoint2DException
public void set(int index,
double y)
throws Point2DException
set in interface XY_DataSetPoint2DExceptionpublic boolean hasPoint(Point2D point)
hasPoint in interface XY_DataSet
public boolean hasPoint(double x,
double y)
hasPoint in interface XY_DataSetpublic 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.
getFirstInterpolatedX in interface DiscretizedFuncy(value - for which interpolated first x value has to be found
public double getFirstInterpolatedX_inLogXLogYDomain(double y)
getFirstInterpolatedX_inLogXLogYDomain in interface DiscretizedFuncy - : 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)
getInterpolatedY in interface DiscretizedFuncx(value - for which interpolated first y value has to be found
public double getInterpolatedY_inLogXLogYDomain(double x)
getInterpolatedY_inLogXLogYDomain in interface DiscretizedFuncx - : 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)
getInterpolatedY_inLogYDomain in interface DiscretizedFuncx - : 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.
deepClone in interface DiscretizedFuncdeepClone in interface XY_DataSetpublic boolean equalXValues(DiscretizedFunc function)
public String toString()
toString in interface XY_DataSettoString in class Objectpublic String getMetadataString()
XY_DataSet
getMetadataString in interface 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)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||