Package elki.math.geometry
Class XYCurve
- java.lang.Object
-
- elki.math.geometry.XYCurve
-
- Direct Known Subclasses:
AUPRCEvaluation.PRCurve
,KNNDistancesSampler.KNNDistanceOrderResult
,OutlierPrecisionAtKCurve.PrecisionAtKCurve
,OutlierSmROCCurve.SmROCResult
,PRGCEvaluation.PRGCurve
,ROCEvaluation.ROCurve
public class XYCurve extends java.lang.Object
An XYCurve is an ordered collection of 2d points, meant for chart generation. Of key interest is the methodaddAndSimplify(double, double)
which tries to simplify the curve while adding points.- Since:
- 0.5.0
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
XYCurve.Itr
Iterator for the curve. 2D, does not follow Java collections style.
-
Field Summary
Fields Modifier and Type Field Description protected DoubleArray
data
X and Y positionsprotected java.lang.String
labelx
Label of X axisprotected java.lang.String
labely
Label of Y axisprotected double
maxdx
Drawing bounds for xprotected double
maxdy
Drawing bounds for yprotected double
maxx
Minimum and maximum for X axisprotected double
maxy
Minimum and maximum for Y axisprotected double
mindx
Drawing bounds for xprotected double
mindy
Drawing bounds for yprotected double
minx
Minimum and maximum for X axisprotected double
miny
Minimum and maximum for Y axisprotected static double
THRESHOLD
Simplification threshold
-
Constructor Summary
Constructors Constructor Description XYCurve()
Constructor.XYCurve(int size)
Constructor with size estimateXYCurve(XYCurve curve)
Constructor, cloning an existing curve.XYCurve(java.lang.String labelx, java.lang.String labely)
Constructor with labelsXYCurve(java.lang.String labelx, java.lang.String labely, int size)
Constructor with size estimate and labels.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(double x, double y)
Add a coordinate pair, but don't simplifyvoid
addAndSimplify(double x, double y)
Add a coordinate pair, performing curve simplification if possible.static double
areaUnderCurve(XYCurve curve)
Compute the area under curve for a curve monotonously increasing in X.java.lang.String
getLabelx()
Get label of x axisjava.lang.String
getLabely()
Get label of y axisdouble
getMaxdx()
upper drawing bound on x axis.double
getMaxdy()
Upper drawing bound on y axis.double
getMaxx()
Maximum on x axis.double
getMaxy()
Maximum on y axis.double
getMindx()
Lower drawing bound on x axis.double
getMindy()
Lower drawing bound on y axis.double
getMinx()
Minimum on x axis.double
getMiny()
Minimum on y axis.double
getX(int off)
Curve X value at given positiondouble
getY(int off)
Curve Y value at given positionboolean
isInDrawingBounds(double x, double y)
Checks if a point is inside the drawing bounds of this curveXYCurve.Itr
iterator()
Get an iterator for the curve.void
rescale(double sx, double sy)
Rescale the graph.void
setAxes(double minx, double miny, double maxx, double maxy)
Set the range of the plot.void
setDrawingBounds(double mindx, double mindy, double maxdx, double maxdy)
Set the drawing bounds of the plot.int
size()
Size of curve.java.lang.String
toString()
-
-
-
Field Detail
-
THRESHOLD
protected static final double THRESHOLD
Simplification threshold- See Also:
- Constant Field Values
-
data
protected DoubleArray data
X and Y positions
-
labelx
protected java.lang.String labelx
Label of X axis
-
labely
protected java.lang.String labely
Label of Y axis
-
minx
protected double minx
Minimum and maximum for X axis
-
maxx
protected double maxx
Minimum and maximum for X axis
-
miny
protected double miny
Minimum and maximum for Y axis
-
maxy
protected double maxy
Minimum and maximum for Y axis
-
mindx
protected double mindx
Drawing bounds for x
-
maxdx
protected double maxdx
Drawing bounds for x
-
mindy
protected double mindy
Drawing bounds for y
-
maxdy
protected double maxdy
Drawing bounds for y
-
-
Constructor Detail
-
XYCurve
public XYCurve(java.lang.String labelx, java.lang.String labely)
Constructor with labels- Parameters:
labelx
- Label for X axislabely
- Label for Y axis
-
XYCurve
public XYCurve(java.lang.String labelx, java.lang.String labely, int size)
Constructor with size estimate and labels.- Parameters:
labelx
- Label for X axislabely
- Label for Y axissize
- Estimated size (initial allocation size)
-
XYCurve
public XYCurve()
Constructor.
-
XYCurve
public XYCurve(int size)
Constructor with size estimate- Parameters:
size
- Estimated size (initial allocation size)
-
XYCurve
public XYCurve(XYCurve curve)
Constructor, cloning an existing curve.- Parameters:
curve
- Curve to clone.
-
-
Method Detail
-
add
public void add(double x, double y)
Add a coordinate pair, but don't simplify- Parameters:
x
- X coordinatey
- Y coordinate
-
addAndSimplify
public void addAndSimplify(double x, double y)
Add a coordinate pair, performing curve simplification if possible.- Parameters:
x
- X coordinatey
- Y coordinate
-
getLabelx
public java.lang.String getLabelx()
Get label of x axis- Returns:
- label of x axis
-
getLabely
public java.lang.String getLabely()
Get label of y axis- Returns:
- label of y axis
-
getMinx
public double getMinx()
Minimum on x axis.- Returns:
- Minimum on X
-
getMaxx
public double getMaxx()
Maximum on x axis.- Returns:
- Maximum on X
-
getMiny
public double getMiny()
Minimum on y axis.- Returns:
- Minimum on Y
-
getMaxy
public double getMaxy()
Maximum on y axis.- Returns:
- Maximum on Y
-
getMindx
public double getMindx()
Lower drawing bound on x axis.- Returns:
- lower drawing bound on X
-
getMaxdx
public double getMaxdx()
upper drawing bound on x axis.- Returns:
- upper drawing bound on X
-
getMindy
public double getMindy()
Lower drawing bound on y axis.- Returns:
- lower drawing bound on Y
-
getMaxdy
public double getMaxdy()
Upper drawing bound on y axis.- Returns:
- upper drawing bound on Y
-
getX
public double getX(int off)
Curve X value at given position- Parameters:
off
- Offset- Returns:
- X value
-
getY
public double getY(int off)
Curve Y value at given position- Parameters:
off
- Offset- Returns:
- Y value
-
rescale
public void rescale(double sx, double sy)
Rescale the graph.- Parameters:
sx
- Scaling factor for X axissy
- Scaling factor for Y axis
-
setAxes
public void setAxes(double minx, double miny, double maxx, double maxy)
Set the range of the plot.- Parameters:
minx
- Minimum xminy
- Minimum ymaxx
- Maximum xmaxy
- Maximum y
-
setDrawingBounds
public void setDrawingBounds(double mindx, double mindy, double maxdx, double maxdy)
Set the drawing bounds of the plot.- Parameters:
mindx
- lower drawing xmindy
- lower drawing ymaxdx
- upper drawing xmaxdy
- upper drawing y
-
isInDrawingBounds
public boolean isInDrawingBounds(double x, double y)
Checks if a point is inside the drawing bounds of this curve- Parameters:
x
- X valuey
- Y value- Returns:
- whether the point is in the drawing bounds
-
size
public int size()
Size of curve.- Returns:
- curve length
-
iterator
public XYCurve.Itr iterator()
Get an iterator for the curve.Note: this is not a Java style iterator, since the only way to get positions is using "next" in Java style. Here, we can have two getters for current values!
Instead, use this style of iteration:
for(XYCurve.Itr it = curve.iterator(); it.valid(); it.advance()) { doSomethingWith(it.getX(), it.getY()); }
- Returns:
- Iterator
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
areaUnderCurve
public static double areaUnderCurve(XYCurve curve)
Compute the area under curve for a curve monotonously increasing in X. You might need to relate this to the total area of the chart.- Parameters:
curve
- Curve- Returns:
- Area under curve.
-
-