Holger's
Java API

com.antelmann.math
Class MyMath

java.lang.Object
  extended by com.antelmann.math.MyMath

public final class MyMath
extends Object

some math related static functions including some useful statistics functions

Author:
Holger Antelmann

Field Summary
static double FIB
          the neares quotient of Fibonacci numbers as double
static Comparator<Number> NUMBER_COMPARATOR
           
 
Method Summary
static String asFormattedString(long bytes, boolean si)
          source taken from the Internet; use it w/ si=true for file sizes
static double average(double... population)
          returns mean(population)
static Comparator<Object> getStringNumberComparator()
           
static boolean isNumber(Object obj)
           
static boolean isNumberType(Class<?> type)
           
static Object max(Object... values)
           
static double maxDouble(double... value)
          returns the greatest element out of the given array
static float maxFloat(float... value)
          returns the greatest element out of the given array
static double maxIndex(double... value)
          returns the index of the greatest element from the given array
static int maxInt(int... value)
          returns the greatest element out of the given array
static long maxLong(long... value)
          returns the greatest element out of the given array
static double mean(double... population)
          returns the mean of the population
static double median(double... population)
          returns the median of the given population
static
<T extends Comparable<?>,N extends Number>
T
median(Map<T,N> map)
           
static Object min(Object... values)
           
static double minDouble(double... value)
          returns the smallest element out of the given array
static double minIndex(double... value)
          returns the index of the smallest element from the given array
static int minInt(int... value)
          returns the greatest element out of the given array
static double range(double... population)
          returns the difference between the max and the min element
static double roundToCurrency(double d)
          Deprecated. use money instead
static BigDecimal roundToScale(BigDecimal b, BigDecimal scale)
           
static double roundToScale(double number, double scale)
          uses IEEEremainder
static Object selectRandom(Collection<?> col)
          randomly returns one element of the given collection (using even chances for each element)
static Object selectRandom(Object... options)
          randomly returns one of the given objects (using even chances for each element)
static double sigmoid(double x)
          produces a double between 0 and 1 with (sigmoid(0) == 0.5) being true
static double sigmoid(double x, double flatteningFactor)
          sigmoid(double x) is the same as sigmoid(double x, 1), large flatteningFactor flattens the curve
static int sign(Number n)
          returns -1, 0, 1 for a negative, zero, positive number
static double softmax(int index, double... x)
          produces a double between 0 and 1 based on the given array x and the index that must be between (0 and x.length) For further information see also: http://www-ccs.ucsd.edu/matlab/toolbox/nnet/softmax.html
static double standardDeviation(double... population)
          returns the standard deviation of the given population based on variance()
static double stdDev(double... sample)
          returns the standard deviation of the given sample based on var()
static double sum(double... population)
          returns the sum of the given population
static int sumOfDigits(long number)
          returns the sum of all individual digits.
static boolean takeChance(double odds)
           
static BigDecimal valueOf(Number n)
           
static double var(double... sample)
          returns the variance of the given sample of a population
static double variance(double... population)
          returns the variance of the given population
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIB

public static final double FIB
the neares quotient of Fibonacci numbers as double

See Also:
Constant Field Values

NUMBER_COMPARATOR

public static final Comparator<Number> NUMBER_COMPARATOR
Method Detail

asFormattedString

public static String asFormattedString(long bytes,
                                       boolean si)
source taken from the Internet; use it w/ si=true for file sizes


takeChance

public static boolean takeChance(double odds)

selectRandom

public static Object selectRandom(Collection<?> col)
randomly returns one element of the given collection (using even chances for each element)


selectRandom

public static Object selectRandom(Object... options)
randomly returns one of the given objects (using even chances for each element)


sumOfDigits

public static int sumOfDigits(long number)
returns the sum of all individual digits. Example: sumOfDigits(123045) returns 15 (1+2+3+4+0+5).


valueOf

public static BigDecimal valueOf(Number n)

sign

public static int sign(Number n)
returns -1, 0, 1 for a negative, zero, positive number


getStringNumberComparator

public static Comparator<Object> getStringNumberComparator()

roundToCurrency

@Deprecated
public static double roundToCurrency(double d)
Deprecated. use money instead

rounds the given number to a standard currency (2 digits after decimal point). To be exact indeed, this method uses the cumbersome approach by parsing a generated String. Note, that this approach is still loaded with potential problems; currencies are still best represented by either long or BigDecimal.

See Also:
Money

roundToScale

public static BigDecimal roundToScale(BigDecimal b,
                                      BigDecimal scale)

roundToScale

public static double roundToScale(double number,
                                  double scale)
uses IEEEremainder


average

public static double average(double... population)
returns mean(population)

See Also:
mean(double[])

mean

public static double mean(double... population)
returns the mean of the population


sum

public static double sum(double... population)
returns the sum of the given population


range

public static double range(double... population)
returns the difference between the max and the min element


median

public static double median(double... population)
returns the median of the given population


variance

public static double variance(double... population)
returns the variance of the given population


var

public static double var(double... sample)
returns the variance of the given sample of a population


standardDeviation

public static double standardDeviation(double... population)
returns the standard deviation of the given population based on variance()

See Also:
variance(double[] population)

stdDev

public static double stdDev(double... sample)
returns the standard deviation of the given sample based on var()

See Also:
var(double[])

max

public static Object max(Object... values)

min

public static Object min(Object... values)

minDouble

public static double minDouble(double... value)
returns the smallest element out of the given array


maxDouble

public static double maxDouble(double... value)
returns the greatest element out of the given array


maxFloat

public static float maxFloat(float... value)
returns the greatest element out of the given array


maxLong

public static long maxLong(long... value)
returns the greatest element out of the given array


maxInt

public static int maxInt(int... value)
returns the greatest element out of the given array


minInt

public static int minInt(int... value)
returns the greatest element out of the given array


maxIndex

public static double maxIndex(double... value)
returns the index of the greatest element from the given array


minIndex

public static double minIndex(double... value)
returns the index of the smallest element from the given array


sigmoid

public static double sigmoid(double x)
produces a double between 0 and 1 with (sigmoid(0) == 0.5) being true


sigmoid

public static double sigmoid(double x,
                             double flatteningFactor)
sigmoid(double x) is the same as sigmoid(double x, 1), large flatteningFactor flattens the curve


softmax

public static double softmax(int index,
                             double... x)
produces a double between 0 and 1 based on the given array x and the index that must be between (0 and x.length) For further information see also: http://www-ccs.ucsd.edu/matlab/toolbox/nnet/softmax.html


median

public static <T extends Comparable<?>,N extends Number> T median(Map<T,N> map)

isNumber

public static boolean isNumber(Object obj)

isNumberType

public static boolean isNumberType(Class<?> type)


(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads