MathUtil¶
-
public final class
MathUtil
¶ A class containing multiple convenient math functions.
Author: Anton Beloglazov
Fields¶
Methods¶
abs¶
-
public static double[]
abs
(double... data)¶ Gets the absolute values of an array of values
Parameters: - data – the array of values
Returns: a new array with the absolute value of each element in the given array.
countNonZeroBeginning¶
-
public static int
countNonZeroBeginning
(double... data)¶ Counts the number of values different of zero at the beginning of an array.
Parameters: - data – the array of numbers
Returns: the number of values different of zero at the beginning of the array
createLinearRegression¶
-
public static SimpleRegression
createLinearRegression
(double[] x, double[] y)¶
createLinearRegression¶
-
public static OLSMultipleLinearRegression
createLinearRegression
(double[][] x, double[] y)¶
doubleToInt¶
-
public static int
doubleToInt
(double value)¶ Converts a double value to an int, using an appropriate rounding function. If the double is negative, it applies
Math.floor(double)
to round the number down. If it’ a positive value, it appliesMath.ceil(double)
to round the number up. This way, a negative double will be converted to a negative int and a positive double will be converted to a positive int.It’s different from using:
Math.round(double)
which always rounds to the next positive integer;Math.floor(double)
which always rounds down; orMath.ceil(double)
which always rounds up. It applies floor for negative values and ceil for positive ones.This method is useful to be used by
Comparator
s which rely on a double attribute to compare a list of objects. Since theComparator.compare(Object,Object)
method must return an int, the method being implemented here converts a double to an int value which can be used by a Comparator.Parameters: - value – the double value to convert
Returns: zero if the double value is zero, a negative int if the double is negative, or a positive int if the double is positive.
getLoessParameterEstimates¶
-
public static double[]
getLoessParameterEstimates
(double... y)¶ Gets the Local Regression (Loess) parameter estimates.
Parameters: - y – the y array
Returns: the Loess parameter estimates
getRobustLoessParameterEstimates¶
-
public static double[]
getRobustLoessParameterEstimates
(double... y)¶ Gets the robust loess parameter estimates.
Parameters: - y – the y array
Returns: the robust loess parameter estimates
getStatistics¶
-
public static DescriptiveStatistics
getStatistics
(Collection<Double> list)¶ Gets an object to compute descriptive statistics for an list of numbers.
Parameters: - list – the list of numbers. Must not be null.
Returns: descriptive statistics for the list of numbers.
getStatistics¶
-
public static DescriptiveStatistics
getStatistics
(double... list)¶ Gets an object to compute descriptive statistics for an array of numbers.
Parameters: - list – the array of numbers. Must not be null.
Returns: descriptive statistics for the array of numbers.
getTricubeBisquareWeights¶
-
public static double[]
getTricubeBisquareWeights
(double... residuals)¶ Gets the tricube bisquare weigths.
Parameters: - residuals – the residuals array
Returns: the tricube bisquare weigths
getTricubeWeights¶
-
public static double[]
getTricubeWeights
(int weightsNumber)¶ Gets the tricube weigths.
Parameters: - weightsNumber – the number of weights
Returns: an array of tricube weigths with n elements
iqr¶
-
public static double
iqr
(double... data)¶ Gets the Interquartile Range (IQR) from an array of numbers.
Parameters: - data – the array of numbers
Returns: the IQR
mad¶
-
public static double
mad
(double... data)¶ Gets the Median Absolute Deviation (MAD) from a array of numbers.
Parameters: - data – the array of numbers
Returns: the mad
mean¶
median¶
-
public static double
median
(Collection<Double> list)¶ Gets the median from a list of numbers.
Parameters: - list – the list of numbers
Returns: the median
median¶
-
public static double
median
(double... list)¶ Gets the median from an array of numbers.
Parameters: - list – the array of numbers
Returns: the median
same¶
-
public static boolean
same
(double first, double second)¶ Checks if two double numbers are equals, considering a precision error or 0.01. That is, if the different between the two numbers are lower or equal to 0.01, they are considered equal.
Parameters: - first – the first number to check
- second – the second number to check
Returns: true if the numbers are equal considering the precision error
same¶
-
public static boolean
same
(double first, double second, double precisionError)¶ Checks if two double numbers are equals, considering a given precision error. That is, if the different between the two numbers are lower or equal to the precision error, they are considered equal.
Parameters: - first – the first number to check
- second – the second number to check
- precisionError – the precision error used to compare the numbers
Returns: true if the numbers are equal considering the precision error