prefuse.util
Class MathLib

java.lang.Object
  extended by prefuse.util.MathLib

public class MathLib
extends java.lang.Object

Library of mathematical constants and methods not included in the Math class.

Author:
jeffrey heer

Field Summary
static double LOG10
          The natural logarithm of 10
static double LOG2
          The natural logarithm of 2
static double TWO_PI
          The value 2 * PI
 
Method Summary
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TWO_PI

public static final double TWO_PI
The value 2 * PI

See Also:
Constant Field Values

LOG10

public static final double LOG10
The natural logarithm of 10


LOG2

public static final double LOG2
The natural logarithm of 2

Method Detail

log2

public static double log2(double x)
The base 2 logarithm of the input value

Parameters:
x - the input value
Returns:
the base 2 logarithm

log10

public static double log10(double x)
The base 10 logarithm of the input value

Parameters:
x - the input value
Returns:
the base 10 logarithm

safeLog10

public 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.

Parameters:
x - the input value
Returns:
the "negative-safe" base 10 logarithm

safeSqrt

public 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.

Parameters:
x - the input value
Returns:
the "negative-safe" square root

interp

public 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.

Parameters:
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.
Returns:
the fractional position of the value within the scale, a double between 0 and 1.

linearInterp

public static double linearInterp(double val,
                                  double min,
                                  double max)
Interpolates a value between a given minimum and maximum value using a linear scale.

Parameters:
val - the interpolation value, a fraction between 0 and 1.0.
min - the minimum value of the interpolation range
max - the maximum value of the interpolation range
Returns:
the resulting interpolated value

logInterp

public 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.

Parameters:
val - the interpolation value, a fraction between 0 and 1.0.
min - the minimum value of the interpolation range
max - the maximum value of the interpolation range
Returns:
the resulting interpolated value

sqrtInterp

public static double sqrtInterp(double val,
                                double min,
                                double max)
Interpolates a value between a given minimum and maximum value using a square root scale.

Parameters:
val - the interpolation value, a fraction between 0 and 1.0.
min - the minimum value of the interpolation range
max - the maximum value of the interpolation range
Returns:
the resulting interpolated value

quantiles

public static double[] quantiles(int n,
                                 double[] values)
Compute the n-quantile boundaries for a set of values. The result is an n+1 size array holding the minimum value in the first entry and then n quantile boundaries in the subsequent entries.

Parameters:
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 quantiles
Returns:
an n+1 array of doubles containing the minimum value and the quantile boundary values, in that order

quantile

public 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. For example, if the input value is the median of the distribution described by the quantile boundaries, this method will return 0.5. As another example, if the quantile boundaries represent percentiles, this value will return the percentile ranking of the input value according to the given boundaries.

Parameters:
val - the value for which to return the quantile ranking
quantiles - an array of quantile boundaries of a distribution
Returns:
the quantile ranking, a value between 0 and 1
See Also:
quantiles(int, double[])


Copyright © 2007 Regents of the University of California