Class MathTools
java.lang.Object
de.uka.ipd.sdq.probfunction.math.util.MathTools
MathTools contains a set of commonly used mathematical functions, that are not provided by the
Java libraries.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
Difference up to which two values are considered as equal. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
asString
(double val) computeCumulativeProbabilities
(List<Double> probabilityList) Returns the cumulative probabilities of the list of input probabilities.static BigDecimal
computeJointProbability
(BigDecimal[] probList, int[] nList) computeLines
(List<IContinuousSample> samples, List<Double> intervals) static double
convertToDouble
(Object value) static boolean
equalsComplex
(org.apache.commons.math.complex.Complex z1, org.apache.commons.math.complex.Complex z2) static boolean
equalsDouble
(double d1, double d2) Compares two doubles.static BigDecimal
factorial
(long n) static double
gcd
(double x, double y) Computes something similar to the greatest common divisor (GCD) of two numbers.static double
Computes the greatest common divisor (GDC) of a set of numbers.static Comparator<IContinuousSample>
static Comparator<ISample>
static boolean
static boolean
less
(double d1, double d2) static boolean
lessOrEqual
(double d1, double d2) static int
nextPowerOfTwo
(int value) Returns the next power of two which is larger or equal to the passedvalue
.static BigDecimal
over
(int n, int k) static BigDecimal
over
(int n, int[] nList) static double
round
(double value, double precision) static double
Compute the sum of probabilities associated with a set of IContinuousSamples.static double
sumOfDoubles
(List<Double> list) Compute the sum of a set Doubles.static double
sumOfSamples
(List<ISample> list) Compute the sum of probabilities associated with a set of ISamples.transformComplexToDouble
(List<org.apache.commons.math.complex.Complex> values) Transforms a list of complex values to a list of double values by throwing away the imaginary part.static List<org.apache.commons.math.complex.Complex>
transformDoubleToComplex
(List<Double> values) Transforms a list of double values to a list of complex values.static List<org.apache.commons.math.complex.Complex>
transformSampleToComplex
(List<ISample> samples)
-
Field Details
-
EPSILON_ERROR
public static final double EPSILON_ERRORDifference up to which two values are considered as equal.- See Also:
-
-
Constructor Details
-
MathTools
public MathTools()
-
-
Method Details
-
gcd
Computes the greatest common divisor (GDC) of a set of numbers.- Parameters:
numbers
- List of numbers for which the GDC shall be computed.- Returns:
- Returns the greatest common divisor of all numbers
-
gcd
public static double gcd(double x, double y) Computes something similar to the greatest common divisor (GCD) of two numbers. Note that the GCD for two doubles is calculates, which is different to the standard definition of GCD.- Parameters:
x
- first numbery
- second number- Returns:
- Returns the GDC of y and x.
-
transformComplexToDouble
public static List<Double> transformComplexToDouble(List<org.apache.commons.math.complex.Complex> values) Transforms a list of complex values to a list of double values by throwing away the imaginary part.- Parameters:
values
- List of complex values to transform.- Returns:
- The real part of the value list as doubles.
-
transformDoubleToComplex
public static List<org.apache.commons.math.complex.Complex> transformDoubleToComplex(List<Double> values) Transforms a list of double values to a list of complex values. The real parts are set to the values in the list, the imaginary part is set to zero.- Parameters:
values
- List of double values to transform.- Returns:
- A list of complex values equivalent to the doubles.
-
equalsDouble
public static boolean equalsDouble(double d1, double d2) Compares two doubles.- Parameters:
d1
-d2
-- Returns:
- True, if the difference between both values is lower than EPSILON_ERROR; false otherwise.
-
equalsComplex
public static boolean equalsComplex(org.apache.commons.math.complex.Complex z1, org.apache.commons.math.complex.Complex z2) -
sumOfCountinuousSamples
Compute the sum of probabilities associated with a set of IContinuousSamples.- Parameters:
list
-- Returns:
- the computed value.
-
sumOfSamples
Compute the sum of probabilities associated with a set of ISamples.- Parameters:
list
-- Returns:
- the computed value.
-
sumOfDoubles
Compute the sum of a set Doubles.- Parameters:
list
-- Returns:
- the computed value.
-
computeCumulativeProbabilities
Returns the cumulative probabilities of the list of input probabilities. The size of the result list might be smaller than the size of the input list, since the function terminates when it reaches 1.0.- Parameters:
probabilityList
-- Returns:
-
computeLines
public static HashMap<Double,Line> computeLines(List<IContinuousSample> samples, List<Double> intervals) - Parameters:
samples
-prob
-- Returns:
-
getContinuousSampleComparator
-
getSampleComparator
-
asString
-
over
-
over
-
computeJointProbability
-
factorial
-
isNumeric
-
transformSampleToComplex
-
convertToDouble
-
round
public static double round(double value, double precision) -
lessOrEqual
public static boolean lessOrEqual(double d1, double d2) -
less
public static boolean less(double d1, double d2) -
nextPowerOfTwo
public static int nextPowerOfTwo(int value) Returns the next power of two which is larger or equal to the passedvalue
.As an example, passing the
value
7 will return 2^3 = 8.- Parameters:
value
- a value greater than 0- Returns:
-