public class MathLib
extends java.lang.Object
Math
class.Modifier and Type | Field and Description |
---|---|
static double |
LOG10
The natural logarithm of 10
|
static double |
LOG2
The natural logarithm of 2
|
static double |
TWO_PI
The value 2 * PI
|
Modifier and Type | Method and Description |
---|---|
static double |
interp(int scale,
double val,
double[] dist)
Interpolates a value within a range using a specified scale,
returning the fractional position of the value within that scale.
|
static double |
linearInterp(double val,
double min,
double max)
Interpolates a value between a given minimum and maximum value using
a linear scale.
|
static double |
log10(double x)
The base 10 logarithm of the input value
|
static double |
log2(double x)
The base 2 logarithm of the input value
|
static double |
logInterp(double val,
double min,
double max)
Interpolates a value between a given minimum and maximum value using
a base-10 logarithmic scale.
|
static double |
quantile(double val,
double[] quantiles)
Get the quantile measure, as a value between 0 and 1, for a given
value and set of quantile boundaries.
|
static double[] |
quantiles(int n,
double[] values)
Compute the n-quantile boundaries for a set of values.
|
static double |
safeLog10(double x)
The "safe" base 10 logarithm of the input value, handling
negative values by simply making them positive and then
negating the return value.
|
static double |
safeSqrt(double x)
The "safe" square root of the input value, handling
negative values by simply making them positive and then
negating the return value.
|
static double |
sqrtInterp(double val,
double min,
double max)
Interpolates a value between a given minimum and maximum value using
a square root scale.
|
public static final double TWO_PI
public static final double LOG10
public static final double LOG2
public static double log2(double x)
x
- the input valuepublic static double log10(double x)
x
- the input valuepublic static double safeLog10(double x)
x
- the input valuepublic static double safeSqrt(double x)
x
- the input valuepublic static double interp(int scale, double val, double[] dist)
scale
- The scale on which to perform the interpolation, one of
Constants.LINEAR_SCALE
,
Constants.LOG_SCALE
,
Constants.SQRT_SCALE
, or
Constants.QUANTILE_SCALE
.val
- the interpolation value, a fraction between 0 and 1.0.dist
- a double array describing the distribution of the data.
For the Constants.QUANTILE_SCALE
option, this should
be a collection of quantile boundaries, as determined by the
quantiles(int, double[])
method. For any other scale type,
the first value of the array must contain the minimum value of the
distribution and the last value of the array must contain the
maximum value of the distribution; all values in between will be
ignored.public static double linearInterp(double val, double min, double max)
val
- the interpolation value, a fraction between 0 and 1.0.min
- the minimum value of the interpolation rangemax
- the maximum value of the interpolation rangepublic static double logInterp(double val, double min, double max)
val
- the interpolation value, a fraction between 0 and 1.0.min
- the minimum value of the interpolation rangemax
- the maximum value of the interpolation rangepublic static double sqrtInterp(double val, double min, double max)
val
- the interpolation value, a fraction between 0 and 1.0.min
- the minimum value of the interpolation rangemax
- the maximum value of the interpolation rangepublic static double[] quantiles(int n, double[] values)
n
- the number of quantile boundaries. For example, a value of 4
will break up the values into quartiles, while a value of 100 will break
up the values into percentiles.values
- the array of double values to divide into quantilespublic static double quantile(double val, double[] quantiles)
val
- the value for which to return the quantile rankingquantiles
- an array of quantile boundaries of a distributionquantiles(int, double[])
Copyright ? 2013 Regents of the University of California