## edu.umbc.cs.maple.utils Class MLUtils

```java.lang.Object
edu.umbc.cs.maple.utils.MLUtils
```

`public class MLUtilsextends java.lang.Object`

A collection of machine learning utility functions.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Version:
0.1
Author:
Eric Eaton (EricEaton@umbc.edu)
University of Maryland Baltimore County

Constructor Summary
`MLUtils()`

Method Summary
`static java.awt.geom.Point2D[]` ```appendSortX(java.awt.geom.Point2D[] pts1, java.awt.geom.Point2D[] pts2)```
Combine two sorted vectors of points into one vector of sorted points.
`static double[]` ```areaBetweenLearningCurves(java.awt.geom.Point2D[] baselineLearningCurve, java.awt.geom.Point2D[] targetLearningCurve)```
Given two learning curves, determines the area between the two curves.
`static double` `computePolygonArea(java.awt.geom.Point2D[] pts)`
Computes the area of the specified polygon.
`static java.awt.geom.Point2D[]` ```cropLineX(java.awt.geom.Point2D[] line, double startingXcoord, double stoppingXcoord)```
Crops a line to the given x-coordinates.
`static java.awt.geom.Point2D[]` ```ensureCurveHasXCoordinates(java.awt.geom.Point2D[] curve, double[] xCoords)```
Ensures that the given curve contains all of the specified x-coordinates.
`static java.awt.geom.Point2D` ```interpolate(java.awt.geom.Point2D[] points, double x)```
Interpolates the given x onto the line of points.
`static java.awt.geom.Point2D` ```interpolate(java.awt.geom.Point2D pt1, java.awt.geom.Point2D pt2, double x)```
Does linear interpolation at x of the line from pt1 to pt2.
`static java.awt.geom.Point2D` ```intersection(java.awt.geom.Line2D lineA, java.awt.geom.Line2D lineB)```
Computes the intersection between two lines.
`static boolean` ```isPointOnLine(java.awt.geom.Line2D line, java.awt.geom.Point2D point)```
Determines whether a given point is on a line.
`static void` `main(java.lang.String[] args)`

`static double` `maxY(java.awt.geom.Point2D[] points)`
Determines the maximum y-coordinate for the set of points.
`static double` `minY(java.awt.geom.Point2D[] points)`
Determines the minimum y-coordinate for the set of points.
`static double` ```normalizedAreaBetweenLearningCurves(java.awt.geom.Point2D[] baselineLearningCurve, java.awt.geom.Point2D[] targetLearningCurve, double bestPerformance)```
Calculates the normalized the area between these two learning curves by the area between the baselineLearningCurve and a horizontal line at the bestPerformance.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### MLUtils

`public MLUtils()`
Method Detail

### normalizedAreaBetweenLearningCurves

```public static double normalizedAreaBetweenLearningCurves(java.awt.geom.Point2D[] baselineLearningCurve,
java.awt.geom.Point2D[] targetLearningCurve,
double bestPerformance)```
Calculates the normalized the area between these two learning curves by the area between the baselineLearningCurve and a horizontal line at the bestPerformance.

Parameters:
`baselineLearningCurve` -
`targetLearningCurve` -
`bestPerformance` -
Returns:
the normalized area between the learning curves

### main

`public static void main(java.lang.String[] args)`

### areaBetweenLearningCurves

```public static double[] areaBetweenLearningCurves(java.awt.geom.Point2D[] baselineLearningCurve,
java.awt.geom.Point2D[] targetLearningCurve)```
Given two learning curves, determines the area between the two curves. This area has a sign based on the relationship between the baseline curve and the target curve. If the target curve is below the baseline, the sign will be negative; otherwise, it will be positive. If it is a mix of above and below, a negative sign would indicate that the target is more below the baseline than above it. Note that the baseline and target learning curves can have different starting and ending points from each other, and different points along the curves.

Parameters:
`baselineLearningCurve` - - the baseline learning curve vertices, in increasing order by x-coordinate
`targetLearningCurve` - - the target learning curve vertices, in increasing order by x-coordinate
Returns:
the area between the curves, the first x coordinate of this area, and the last x coordinate of this area.

### ensureCurveHasXCoordinates

```public static java.awt.geom.Point2D[] ensureCurveHasXCoordinates(java.awt.geom.Point2D[] curve,
double[] xCoords)```
Ensures that the given curve contains all of the specified x-coordinates.

Parameters:
`curve` - a curve specified by a set of points in sorted order by x-coordinate
`xCoords` - a set of x-coordinates, sorted in increasing order
Returns:
a curve containing all of the original points and any missing x-coordinates

### computePolygonArea

`public static double computePolygonArea(java.awt.geom.Point2D[] pts)`
Computes the area of the specified polygon.

Parameters:
`pts` - the vertices specifying the polygon.
Returns:
the area of the specified polygon.

### intersection

```public static java.awt.geom.Point2D intersection(java.awt.geom.Line2D lineA,
java.awt.geom.Line2D lineB)```
Computes the intersection between two lines. The calculated point is approximate, since integers are used. If you need a more precise result, use doubles everywhere. Modified from original version (by Alexander Hristov) by Eric Eaton. (c) 2007 Alexander Hristov. Use Freely (LGPL license). http://www.ahristov.com

Parameters:
`lineA` - the first line
`lineB` - the second line
Returns:
point where the segments intersect, or null if they don't

### isPointOnLine

```public static boolean isPointOnLine(java.awt.geom.Line2D line,
java.awt.geom.Point2D point)```
Determines whether a given point is on a line.

Parameters:
`line` -
`point` -
Returns:
whether the specified point is on the line

### appendSortX

```public static java.awt.geom.Point2D[] appendSortX(java.awt.geom.Point2D[] pts1,
java.awt.geom.Point2D[] pts2)```
Combine two sorted vectors of points into one vector of sorted points.

Parameters:
`pts1` -
`pts2` -
Returns:
the vector of sorted points from pts1 and pts2

### cropLineX

```public static java.awt.geom.Point2D[] cropLineX(java.awt.geom.Point2D[] line,
double startingXcoord,
double stoppingXcoord)```
Crops a line to the given x-coordinates.

Parameters:
`line` -
`startingXcoord` -
`stoppingXcoord` -
Returns:
the line cropped to the specified x-coordinates

### interpolate

```public static java.awt.geom.Point2D interpolate(java.awt.geom.Point2D pt1,
java.awt.geom.Point2D pt2,
double x)```
Does linear interpolation at x of the line from pt1 to pt2.

Parameters:
`pt1` - one endpoint of the line.
`pt2` - another endpoint of the line.
`x` - the x-coordinate of the interpolated point.
Returns:
the desired interpolated point.

### interpolate

```public static java.awt.geom.Point2D interpolate(java.awt.geom.Point2D[] points,
double x)```
Interpolates the given x onto the line of points.

Parameters:
`points` -
`x` -
Returns:
x interpolated onto the line defined by the points

### minY

`public static double minY(java.awt.geom.Point2D[] points)`
Determines the minimum y-coordinate for the set of points.

Parameters:
`points` -
Returns:
the minimum y-coordinate of the points

### maxY

`public static double maxY(java.awt.geom.Point2D[] points)`
Determines the maximum y-coordinate for the set of points.

Parameters:
`points` -
Returns:
the maximum y-coordinate of the points