public class EvenlyDiscretizedFunc extends AbstractDiscretizedFunc
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 x-values 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 x-min value, x-max value, and the delta spacing between x values. This is enough to calculate any x-value 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 mid-point of the histogram interval
| Modifier and Type | Field and Description |
|---|---|
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 x-value in this series
|
protected double |
minX
The minimum x-value 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
|
C, D, toleranceinfo, name, xAxisName, yAxisName| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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
|
DiscretizedFunc |
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 y-points
array.
|
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 x-values
|
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 index of this DataPoint based on it's x any y value both the
x-value and y-values 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 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)
This function interpolates the y-axis value corresponding to the given
value of x
|
double |
getMaxX()
Returns the maximum x-value in this series.
|
double |
getMaxY()
Returns the maximum y-value 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 x-value in this series.
|
double |
getMinY()
Returns the minimum y-value 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.
|
double |
getY(double x)
Returns they-value associated with this x-value.
|
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 x-value 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 x-value in this
list, and the y value is equal to y value in the list.
|
void |
set(double x,
double y)
Sets the y-value 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.
|
calcSumOfY_Vals, equals, getTolerance, scale, setTolerancegetClosestX, getInfo, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, iterator, name, setInfo, setName, setXAxisName, setYAxisName, xValues, yValuesclone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetClosestX, getInfo, getXAxisName, getXValuesIterator, getYAxisName, getYValuesIterator, setInfo, setName, setXAxisName, setYAxisName, xValues, yValuesforEach, iterator, spliteratorprotected double[] points
protected double minX
protected double maxX
protected double delta
protected int num
protected boolean first
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 valuepublic 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 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()
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 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 getClosestY(double x)
XY_DataSetgetClosestY in interface XY_DataSetgetClosestY in class AbstractXY_DataSetpublic 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 DiscretizedFunc 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_DataSetareAllXValuesInteger in class AbstractXY_DataSettolerance - value to consider rounding errorspublic boolean equalXAndYValues(DiscretizedFunc function)
public String toString()
toString in interface XY_DataSettoString in class Objectpublic String getMetadataString()
XY_DataSetpublic boolean hasPoint(Point2D point)
public boolean hasPoint(double x,
double y)
public int getIndex(Point2D point)