com.net2plan.utils

## Class DoubleUtils

• public class DoubleUtils
extends Object

Provides extra functionality for double primitives.

Since:
0.2.0
Author:
Pablo Pavon-Marino, Jose-Luis Izquierdo-Zaragoza
• ### Method Summary

All Methods
Modifier and Type Method and Description
static double[] arrayOf(double... values)
Generates a double[] from comma-separated values.
static Double[] asObjectArray(double[] array)
Converts from a double array to a Double array.
static double[] asPrimitiveArray(Double[] array)
Converts from a Double array to a double array.
static double average(Collection<Double> collection)
Returns the average value of a collection.
static double average(double[] array)
Returns the average value of an array.
static <A> double average(Map<A,Double> map)
Returns the average of the map values.
static double averageNonZeros(double[] array)
Returns the average value only among non-zero values
static double[] ceil(double[] array)
Rounds up each element of a given double array.
static double[] concatenate(double[]... arrays)
Concatenates a series of arrays.
static double[] constantArray(int N, double value)
Returns an array filled with a given value.
static <A> Map<A,Double> constantMap(Set<A> identifiers, double value)
Returns a map filled with a given value.
static boolean contains(double[] array, double value)
Checks if an input array contains a given value
static boolean containsAll(double[] container, double[] array)
Checks if an array contains all numbers from another one.
static boolean containsAny(double[] container, double[] array)
Checks whether any element of an array is present in another one.
static <A extends Number>
Map<A,Double>
convertArray2Map(Set<A> identifiers, double[] array)
Returns a map containing the association of each identifier with its corresponding value within the array (in linear order).
static <A extends Number,B extends Number>
Map<Pair<A,B>,Double>
convertMatrix2Map(Set<A> rowIdentifiers, Set<B> columnIdentifiers, DoubleMatrix2D matrix)
Returns a map containing the association of each identifier pair with its corresponding value within the table (in linear order).
static <A extends Number,B extends Number>
Map<Pair<A,B>,Double>
convertTable2Map(Set<A> rowIdentifiers, Set<B> columnIdentifiers, double[][] table)
Returns a map containing the association of each identifier pair with its corresponding value within the table (in linear order).
static double[] copy(double[] array)
Returns a deep copy of the input array.
static double[][] copy(double[][] array)
Returns a deep copy of the input array.
static double[] divide(double[] array, double value)
Divides all elements in an array by a scalar.
static double[] divide(double[] array1, double[] array2)
Divides two arrays element-to-element
static <A> Map<A,Double> divide(Map<A,Double> map, double value)
Divides all elements in a map by a scalar.
static <A> Map<A,Double> divide(Map<A,Double> map1, Map<A,Double> map2)
Returns the element-wise quotient of two maps.
static double[] divideNonSingular(double[] array1, double[] array2)
Divides two arrays element-to-element, but when numerator and denominator = 0, returns 0 instead of a singularity (NaN)
static int[] find(double[] array, double value, Constants.SearchType searchType)
Returns the position(s) where a given value can be found into an array.
static double[] floor(double[] array)
Rounds down each element of a given double array.
static String formatAndRemoveTrailingZeros(double value, int numDecimals)
Converts a double to String (using '%f' modifier) and remove trailing zeros.
static double gcd(Collection<Double> collection)
Computes the greatest common divisor of an input collection.
static double gcd(double[] array)
Computes the greatest common divisor of a double array.
static double[] intersect(double[]... arrays)
Returns the intersection vector of a series of input arrays.
static boolean isEqualWithinAbsoluteTolerance(double pattern, double value, double tolerance)
Checks if a given value is within a tolerance margin compared to a given pattern.
static boolean isEqualWithinRelativeTolerance(double pattern, double value, double tolerance)
Checks if the relative difference between a given value and a pattern is within a tolerance margin.
static String join(double[] array, String separator)
Joins the elements in an input array using a given separator.
static List<Double> listOf(double... values)
Returns a list of the comma-separated input values.
static int[] maxIndexes(double[] array, Constants.SearchType searchType)
Returns the position(s) in which the maximum value is found.
static int[] maxIndexes(double[] array, Constants.SearchType searchType, double precisionFactor)
Returns the position(s) in which the maximum value is found.
static <A> Set<A> maxIndexes(Map<A,Double> map, Constants.SearchType searchType)
Returns the position(s) in which the maximum value is found.
static int[][] maxMinIndexes(double[] array, Constants.SearchType searchType)
Returns the position(s) in which the maximum/minimum values are found.
static int[][] maxMinIndexes(double[] array, Constants.SearchType searchType, double precisionFactor)
Returns the position(s) in which the maximum/minimum values are found.
static double[] maxMinValues(Collection<Double> collection)
Returns the maximum/minimum values of an input collection.
static double[] maxMinValues(double[] array)
Returns the maximum/minimum values of an input array.
static <A> double[] maxMinValues(Map<A,Double> map)
Returns the maximum/minimum values of an input array.
static double maxValue(Collection<Double> collection)
Returns the maximum value in the input collection.
static double maxValue(double[] array)
Returns the maximum value in the input array.
static double maxValue(double[][] array)
Returns the maximum value in the input array.
static <A> double maxValue(Map<A,Double> map)
Returns the maximum value in the input array.
static int[] minIndexes(double[] array, Constants.SearchType searchType)
Returns the position(s) in which the minimum value is found.
static <A> Set<A> minIndexes(Map<A,Double> map, Constants.SearchType searchType)
Returns the position(s) in which the minimum value is found.
static double minValue(Collection<Double> collection)
Returns the minimum value in the input collection.
static double minValue(double[] array)
Returns the minimum value in the input array.
static double minValue(double[][] matrix)
Returns the minimum value in the input matrix.
static <A> double minValue(Map<A,Double> map)
Returns the minimum value in the input map.
static double[][] mult(double[][] matrix, double value)
Multiplies all elements in a matrix by a scalar.
static double[] mult(double[] array, double value)
Multiplies all elements in an array by a scalar.
static double[] mult(double[] array1, double[] array2)
Multiplies two arrays element-to-element.
static <A> Map<A,Double> mult(Map<A,Double> map, double value)
Multiplies all elements in an array by a scalar.
static <A> Map<A,Double> mult(Map<A,Double> map1, Map<A,Double> map2)
Returns the element-wise product of two maps.
static double[] ones(int N)
Returns an array filled with ones.
static <A> Map<A,Double> ones(Set<A> identifiers)
Returns a map filled with ones.
Reads a 2D matrix from a file.
static void reverse(double[] array)
Reverses the order of the elements of the input array (it will be overriden).
static double[] round(double[] array, int decimals)
Rounds a number to the nearest double given the number of required decimal places.
static double round(double number, int decimals)
Rounds a number to the closest double given the number of required decimal places.
static double scalarProduct(double[] array1, double[] array2)
Scalar product of two vectors.
static <A> double scalarProduct(Map<A,Double> map1, Map<A,Double> map2)
Scalar product of two maps.
static double[] select(double[] array, int[] indexes)
Returns a set of selected elements from an input array.
static double[] selectColumn(double[][] array, int column)
Returns a column of a bidimensional input array.
static double[] selectRow(double[][] array, int row)
Returns a row of a bidimensional input array.
static double[] setdiff(double[]... arrays)
Returns the elements contained in the first array, but not any of the others.
static Set<Double> setOf(double... values)
Returns a list of the comma-separated input values.
static void sort(double[] array, Constants.OrderingType orderingType)
Sorts the input array (it will be overriden).
static int[] sortIndexes(double[] array, Constants.OrderingType orderingType)
Sorts indexes of the array into ascending/descending order in a stable way.
static double std(Collection<Double> collection)
Returns the standard deviation of a collection using the Welford's method.
static double std(double[] array)
Returns the standard deviation of an array using the Welford's method.
static <A> double std(Map<A,Double> map)
Returns the standard deviation of values of a map using the Welford's method.
static double[] substract(double[] array1, double[] array2)
Returns the element-wise substraction of two arrays.
static double sum(Collection<Double> collection)
Returns the sum of all elements in the input collection.
static double sum(double[] array)
Returns the sum of all elements in the input array.
static double sum(double[][] matrix)
Returns the sum of all elements in the input matrix.
static double[] sum(double[] array1, double[] array2)
Returns the element-wise sum of two arrays.
static <A> double sum(Map<A,Double> map)
Returns the sum of all elements in the input collection.
static <A> Map<A,Double> sum(Map<A,Double> map1, Map<A,Double> map2)
Returns the element-wise sum of two maps.
static double[] toArray(Collection<Double> list)
Converts a collection (List, Set...) of Double objects to a double array.
static double[] toArray(String[] list)
Converts an array of String with the values, into a double array.
static int[] toIntArray(double[] array)
Converts a double array to an int array
static List<Double> toList(double[] array)
Converts from a double array to a list.
static String toString(double[] array)
Converts the array into an String of space separated values.
static double[] union(double[]... arrays)
Returns an array with all elements in input arrays (no repetitions).
static double[] unique(double[] array)
Returns the same values of the input array but with no repetitions.
static double[] zeros(int N)
Returns an array filled with zeros.
static <A> Map<A,Double> zeros(Set<A> identifiers)
Returns a map filled with zeros.
• ### Method Detail

• #### arrayOf

public static double[] arrayOf(double... values)
Generates a double[] from comma-separated values.
Parameters:
values - Comma-separated double values
Returns:
double[]
• #### asObjectArray

public static Double[] asObjectArray(double[] array)
Converts from a double array to a Double array.
Parameters:
array - double array
Returns:
Equivalent Double array
• #### asPrimitiveArray

public static double[] asPrimitiveArray(Double[] array)
Converts from a Double array to a double array.
Parameters:
array - Double array
Returns:
Equivalent double array
• #### average

public static double average(Collection<Double> collection)
Returns the average value of a collection.
Parameters:
collection - Input collection
Returns:
Average value (or zero, if collection is empty)
• #### average

public static double average(double[] array)
Returns the average value of an array.
Parameters:
array - Input array
Returns:
Average value (or zero, if array is empty)
• #### average

public static <A> double average(Map<A,Double> map)
Returns the average of the map values.
Type Parameters:
A - Key type
Parameters:
map - Input map
Returns:
Average value (or zero, if map is empty)
• #### averageNonZeros

public static double averageNonZeros(double[] array)
Returns the average value only among non-zero values
Parameters:
array - Input array
Returns:
Average value among non-zero values
• #### ceil

public static double[] ceil(double[] array)
Rounds up each element of a given double array.
Parameters:
array - Array to be rounded up
Returns:
Rounded up array
• #### concatenate

public static double[] concatenate(double[]... arrays)
Concatenates a series of arrays.
Parameters:
arrays - List of arrays
Returns:
Concatenated array
• #### constantArray

public static double[] constantArray(int N,
double value)
Returns an array filled with a given value.
Parameters:
N - Number of elements
value - Value for all elements
Returns:
An array of length N with the given value
• #### constantMap

public static <A> Map<A,Double> constantMap(Set<A> identifiers,
double value)
Returns a map filled with a given value.
Type Parameters:
A - Key type
Parameters:
identifiers - Set of map keys
value - Value for all elements
Returns:
A map with the given value in each entry
• #### contains

public static boolean contains(double[] array,
double value)
Checks if an input array contains a given value
Parameters:
array - Input array
value - Value to search
Returns:
true if value is present in array, and false otherwise. If array is empty, it will return false
• #### containsAll

public static boolean containsAll(double[] container,
double[] array)
Checks if an array contains all numbers from another one.
Parameters:
container - Container array
array - Array with elements to be checked
Returns:
true if all elements in array are present in container, and false otherwise. If container is empty, it will return false
• #### containsAny

public static boolean containsAny(double[] container,
double[] array)
Checks whether any element of an array is present in another one. It is equivalent to assert if intersection(array1, array2).length == 0.
Parameters:
container - Container array
array - Array with elements to be checked
Returns:
true if any element in array is present in container, and false otherwise. If container is empty, it will return false
• #### convertArray2Map

public static <A extends NumberMap<A,Double> convertArray2Map(Set<A> identifiers,
double[] array)
Returns a map containing the association of each identifier with its corresponding value within the array (in linear order). First element in the array will be associated to the first identifier in the set (in iteration order), second element in the array to the second element in the set, and so on.
Type Parameters:
A - Key type
Parameters:
identifiers - Set of identifier in ascending iterator order (duplicated and null values are not allowed)
array - Input array
Returns:
Map
• #### convertMatrix2Map

public static <A extends Number,B extends NumberMap<Pair<A,B>,Double> convertMatrix2Map(Set<A> rowIdentifiers,
Set<B> columnIdentifiers,
DoubleMatrix2D matrix)
Returns a map containing the association of each identifier pair with its corresponding value within the table (in linear order). First element in the table will be associated to the first identifier pair (in iteration order), second element in the table to the second identifier pair, and so on.
Type Parameters:
A - Row key type
B - Column key type
Parameters:
rowIdentifiers - Set of row identifiers in ascending iterator order (null values are not allowed)
columnIdentifiers - Set of column identifiers in ascending iterator order (duplicated and null values are not allowed)
matrix - Input matrix
Returns:
Map
• #### convertTable2Map

public static <A extends Number,B extends NumberMap<Pair<A,B>,Double> convertTable2Map(Set<A> rowIdentifiers,
Set<B> columnIdentifiers,
double[][] table)
Returns a map containing the association of each identifier pair with its corresponding value within the table (in linear order). First element in the table will be associated to the first identifier pair (in iteration order), second element in the table to the second identifier pair, and so on.
Type Parameters:
A - Row key type
B - Column key type
Parameters:
rowIdentifiers - Set of row identifiers in ascending iterator order (null values are not allowed)
columnIdentifiers - Set of column identifiers in ascending iterator order (duplicated and null values are not allowed)
table - Input table
Returns:
Map
• #### copy

public static double[] copy(double[] array)
Returns a deep copy of the input array.
Parameters:
array - Input array
Returns:
Deep copy of array
• #### copy

public static double[][] copy(double[][] array)
Returns a deep copy of the input array.
Parameters:
array - Input array
Returns:
Deep copy of array
• #### divide

public static double[] divide(double[] array,
double value)
Divides all elements in an array by a scalar.
Parameters:
array - Input array
value - Scalar
Returns:
A new array containing the input elements divided by the scalar
• #### divide

public static double[] divide(double[] array1,
double[] array2)
Divides two arrays element-to-element
Parameters:
array1 - Numerator
array2 - Denominator
Returns:
The element-wise division of the input arrays
• #### divide

public static <A> Map<A,Double> divide(Map<A,Double> map,
double value)
Divides all elements in a map by a scalar.
Type Parameters:
A - Key type
Parameters:
map - Input map
value - Scalar
Returns:
A new map containing the input elements divided by the scalar
• #### divide

public static <A> Map<A,Double> divide(Map<A,Double> map1,
Map<A,Double> map2)
Returns the element-wise quotient of two maps.
Type Parameters:
A - Key type
Parameters:
map1 - Input map 1
map2 - Input map 2
Returns:
A new map with the element-wise quotient
• #### divideNonSingular

public static double[] divideNonSingular(double[] array1,
double[] array2)
Divides two arrays element-to-element, but when numerator and denominator = 0, returns 0 instead of a singularity (NaN)
Parameters:
array1 - Numerator
array2 - Denominator
Returns:
The element-wise division of the input arrays
• #### find

public static int[] find(double[] array,
double value,
Constants.SearchType searchType)
Returns the position(s) where a given value can be found into an array.
Parameters:
array - Input array
value - Value to be searched for
searchType - Indicates whether the first, the last, or all occurrences are returned
Returns:
Position(s) in which the given value can be found
• #### floor

public static double[] floor(double[] array)
Rounds down each element of a given double array.
Parameters:
array - Array to be rounded down
Returns:
Rounded down array
• #### formatAndRemoveTrailingZeros

public static String formatAndRemoveTrailingZeros(double value,
int numDecimals)
Converts a double to String (using '%f' modifier) and remove trailing zeros.
Parameters:
value - Input value
numDecimals - Maximum number of decimal digits
Returns:
Formatted value wihout trailiing zeros
• #### gcd

public static double gcd(Collection<Double> collection)
Computes the greatest common divisor of an input collection.
Parameters:
collection - Input collection
Returns:
The greatest common divisor. By convention, gcd(0, 0) is equal to zero and gcd([]) is equal to one
• #### gcd

public static double gcd(double[] array)
Computes the greatest common divisor of a double array.
Parameters:
array - Input array
Returns:
The greatest common divisor. By convention, gcd(0, 0) is equal to zero and gcd([]) is equal to one
• #### intersect

public static double[] intersect(double[]... arrays)
Returns the intersection vector of a series of input arrays. There is no order guarantee.
Parameters:
arrays - Vector of input arrays
Returns:
Intersection vector of input arrays
• #### isEqualWithinAbsoluteTolerance

public static boolean isEqualWithinAbsoluteTolerance(double pattern,
double value,
double tolerance)
Checks if a given value is within a tolerance margin compared to a given pattern.
Parameters:
pattern - Pattern value
value - Value to compare with pattern
tolerance - Tolerance margin
Returns:
true if value is within the tolerance, and false otherwise
• #### isEqualWithinRelativeTolerance

public static boolean isEqualWithinRelativeTolerance(double pattern,
double value,
double tolerance)
Checks if the relative difference between a given value and a pattern is within a tolerance margin.
Parameters:
pattern - Pattern value
value - Value to compare with pattern
tolerance - Tolerance margin
Returns:
true if value is within the tolerance, and false otherwise
• #### join

public static String join(double[] array,
String separator)
Joins the elements in an input array using a given separator. It is an improved version of Arrays.toString().
Parameters:
array - Input array
separator - Separator
Returns:
String representation of the input array
• #### listOf

public static List<Double> listOf(double... values)
Returns a list of the comma-separated input values.
Parameters:
values - Comma-separated input values
Returns:
List of values (iteration order equal to insertion order)
• #### maxIndexes

public static int[] maxIndexes(double[] array,
Constants.SearchType searchType)
Returns the position(s) in which the maximum value is found.
Parameters:
array - Input array
searchType - Indicates whether the first, the last, or all maximum positions are returned
Returns:
Position(s) in which the maximum value is found
• #### maxIndexes

public static int[] maxIndexes(double[] array,
Constants.SearchType searchType,
double precisionFactor)
Returns the position(s) in which the maximum value is found.
Parameters:
array - Input array
searchType - Indicates whether the first, the last, or all maximum positions are returned
precisionFactor - Tolerance factor (values with absolute difference lower or equal than precisionFactor will be considered equal)
Returns:
Position(s) in which the maximum value is found
• #### maxIndexes

public static <A> Set<A> maxIndexes(Map<A,Double> map,
Constants.SearchType searchType)
Returns the position(s) in which the maximum value is found.
Type Parameters:
A - Key type
Parameters:
map - Input map
searchType - Indicates whether the first, the last, or all maximum positions are returned
Returns:
Position(s) in which the maximum value is found
• #### maxMinIndexes

public static int[][] maxMinIndexes(double[] array,
Constants.SearchType searchType)

Returns the position(s) in which the maximum/minimum values are found.

out[0] are the maximum positions, while out[1] are the minimum positions

Parameters:
array - Input array
searchType - Indicates whether the first, the last, or all maximum positions are returned
Returns:
Position(s) in which the maximum/minimum value are found.
• #### maxMinIndexes

public static int[][] maxMinIndexes(double[] array,
Constants.SearchType searchType,
double precisionFactor)

Returns the position(s) in which the maximum/minimum values are found.

out[0] are the maximum positions, while out[1] are the minimum positions

Parameters:
array - Input array
searchType - Indicates whether the first, the last, or all maximum positions are returned
precisionFactor - Tolerance factor (values with absolute difference lower or equal than precisionFactor will be considered equal)
Returns:
Position(s) in which the maximum/minimum value are found.
• #### maxMinValues

public static double[] maxMinValues(Collection<Double> collection)
Returns the maximum/minimum values of an input collection.
Parameters:
collection - Input collection
Returns:
Maximum/minimum values
• #### maxMinValues

public static double[] maxMinValues(double[] array)
Returns the maximum/minimum values of an input array.
Parameters:
array - Input array
Returns:
Maximum/minimum values
• #### maxMinValues

public static <A> double[] maxMinValues(Map<A,Double> map)
Returns the maximum/minimum values of an input array.
Type Parameters:
A - map key
Parameters:
map - Input map
Returns:
Maximum/minimum values
• #### maxValue

public static double maxValue(Collection<Double> collection)
Returns the maximum value in the input collection.
Parameters:
collection - Input collection
Returns:
Maximum value
• #### maxValue

public static double maxValue(double[] array)
Returns the maximum value in the input array.
Parameters:
array - Input array
Returns:
Maximum value
• #### maxValue

public static double maxValue(double[][] array)
Returns the maximum value in the input array.
Parameters:
array - Input array
Returns:
Maximum value
• #### maxValue

public static <A> double maxValue(Map<A,Double> map)
Returns the maximum value in the input array.
Type Parameters:
A - Key type
Parameters:
map - Input map
Returns:
Maximum value
• #### minIndexes

public static int[] minIndexes(double[] array,
Constants.SearchType searchType)
Returns the position(s) in which the minimum value is found.
Parameters:
array - Input array
searchType - Indicates whether the first, the last, or all minimum positions are returned
Returns:
Position(s) in which the minimum value is found
• #### minIndexes

public static <A> Set<A> minIndexes(Map<A,Double> map,
Constants.SearchType searchType)
Returns the position(s) in which the minimum value is found.
Type Parameters:
A - Key type
Parameters:
map - Input map
searchType - Indicates whether the first, the last, or all minimum positions are returned
Returns:
Position(s) in which the minimum value is found
• #### minValue

public static double minValue(Collection<Double> collection)
Returns the minimum value in the input collection.
Parameters:
collection - Input collection
Returns:
Minimum value
• #### minValue

public static double minValue(double[] array)
Returns the minimum value in the input array.
Parameters:
array - Input array
Returns:
Minimum value
• #### minValue

public static double minValue(double[][] matrix)
Returns the minimum value in the input matrix.
Parameters:
matrix - Input matrix
Returns:
Minimum value
• #### minValue

public static <A> double minValue(Map<A,Double> map)
Returns the minimum value in the input map.
Type Parameters:
A - Key type
Parameters:
map - Input map
Returns:
Minimum value
• #### mult

public static double[][] mult(double[][] matrix,
double value)
Multiplies all elements in a matrix by a scalar.
Parameters:
matrix - Input array
value - Scalar
Returns:
A new matrix containing the input elements multiplied by the scalar
• #### mult

public static double[] mult(double[] array,
double value)
Multiplies all elements in an array by a scalar.
Parameters:
array - Input array
value - Scalar
Returns:
A new array containing the input elements multiplied by the scalar
• #### mult

public static double[] mult(double[] array1,
double[] array2)
Multiplies two arrays element-to-element.
Parameters:
array1 - Input array 1
array2 - Input array 2
Returns:
The element-wise multiplication of the input arrays
• #### mult

public static <A> Map<A,Double> mult(Map<A,Double> map,
double value)
Multiplies all elements in an array by a scalar.
Type Parameters:
A - Key type
Parameters:
map - Input map
value - Scalar
Returns:
A new map containing the input elements multiplied by the scalar
• #### mult

public static <A> Map<A,Double> mult(Map<A,Double> map1,
Map<A,Double> map2)
Returns the element-wise product of two maps.
Type Parameters:
A - Key type
Parameters:
map1 - Input map 1
map2 - Input map 2
Returns:
A new map with the element-wise product
• #### ones

public static double[] ones(int N)
Returns an array filled with ones.
Parameters:
N - Number of elements
Returns:
An all-one array of length N
• #### ones

public static <A> Map<A,Double> ones(Set<A> identifiers)
Returns a map filled with ones.
Type Parameters:
A - Key type
Parameters:
identifiers - Set of map keys
Returns:
An all-one map

Reads a 2D matrix from a file. Each line in the file is a row of the matrix. Items can be separated by spaces or tabs. Lines starting with '#' are skipped.
Parameters:
file - Input file
Returns:
A 2D matrix
• #### reverse

public static void reverse(double[] array)
Reverses the order of the elements of the input array (it will be overriden).
Parameters:
array - Input array
• #### round

public static double[] round(double[] array,
int decimals)
Rounds a number to the nearest double given the number of required decimal places.
Parameters:
array - Array to be rounded
decimals - Decimal places
Returns:
Rounded number
• #### round

public static double round(double number,
int decimals)
Rounds a number to the closest double given the number of required decimal places.
Parameters:
number - Number to be rounded
decimals - Decimal places
Returns:
Rounded number
Since:
0.2.2
• #### scalarProduct

public static double scalarProduct(double[] array1,
double[] array2)
Scalar product of two vectors.
Parameters:
array1 - Input array 1
array2 - Input array 2
Returns:
The scalar product of the input arrays
• #### scalarProduct

public static <A> double scalarProduct(Map<A,Double> map1,
Map<A,Double> map2)
Scalar product of two maps.
Type Parameters:
A - Key type
Parameters:
map1 - Input map 1
map2 - Input map 2
Returns:
The scalar product of the input maps
• #### select

public static double[] select(double[] array,
int[] indexes)
Returns a set of selected elements from an input array. It is not backed in the input array, thus changes in this array are not reflected in the input array.
Parameters:
array - Input array
indexes - Position of elements to be selected.
Returns:
Set of elements in the order given by indexes
• #### selectColumn

public static double[] selectColumn(double[][] array,
int column)
Returns a column of a bidimensional input array.
Parameters:
array - Input array
column - Column
Returns:
Column of an array
• #### selectRow

public static double[] selectRow(double[][] array,
int row)
Returns a row of a bidimensional input array.
Parameters:
array - Input array
row - Row
Returns:
Row of an array
• #### setdiff

public static double[] setdiff(double[]... arrays)
Returns the elements contained in the first array, but not any of the others.
Parameters:
arrays - Input arrays
Returns:
Difference set
• #### setOf

public static Set<Double> setOf(double... values)
Returns a list of the comma-separated input values.
Parameters:
values - Comma-separated input values
Returns:
List of values (iteration order equal to insertion order)
• #### sort

public static void sort(double[] array,
Constants.OrderingType orderingType)
Sorts the input array (it will be overriden).
Parameters:
array - Input array
orderingType - Ascending or descending
• #### sortIndexes

public static int[] sortIndexes(double[] array,
Constants.OrderingType orderingType)
Sorts indexes of the array into ascending/descending order in a stable way. Stable means that index order doesn't change if values are the same.
Parameters:
array - Array to be sorted
orderingType - Ascending or descending
Returns:
Sorted indexes
• #### std

public static double std(Collection<Double> collection)
Returns the standard deviation of a collection using the Welford's method.
Parameters:
collection - Collection of numbers
Returns:
Standard deviation (or zero, if collection is empty
• #### std

public static double std(double[] array)
Returns the standard deviation of an array using the Welford's method.
Parameters:
array - Input array
Returns:
Standard deviation
• #### std

public static <A> double std(Map<A,Double> map)
Returns the standard deviation of values of a map using the Welford's method.
Type Parameters:
A - Key type
Parameters:
map - Input map
Returns:
Standard deviation
• #### substract

public static double[] substract(double[] array1,
double[] array2)
Returns the element-wise substraction of two arrays.
Parameters:
array1 - Input array 1
array2 - Input array 2
Returns:
A new array with the element-wise subtraction
• #### sum

public static double sum(Collection<Double> collection)
Returns the sum of all elements in the input collection.
Parameters:
collection - Input collection
Returns:
Sum of all collection values
• #### sum

public static double sum(double[] array)
Returns the sum of all elements in the input array.
Parameters:
array - Input array
Returns:
Sum of all array elements
• #### sum

public static double sum(double[][] matrix)
Returns the sum of all elements in the input matrix.
Parameters:
matrix - Input matrix
Returns:
Sum of all matrix elements
• #### sum

public static double[] sum(double[] array1,
double[] array2)
Returns the element-wise sum of two arrays.
Parameters:
array1 - Input array 1
array2 - Input array 2
Returns:
A new array with the element-wise sum
• #### sum

public static <A> double sum(Map<A,Double> map)
Returns the sum of all elements in the input collection.
Type Parameters:
A - Key type
Parameters:
map - Input map
Returns:
Sum of all map values
• #### sum

public static <A> Map<A,Double> sum(Map<A,Double> map1,
Map<A,Double> map2)
Returns the element-wise sum of two maps.
Type Parameters:
A - Key type
Parameters:
map1 - Input map 1
map2 - Input map 2
Returns:
A new map with the element-wise sum
• #### toArray

public static double[] toArray(Collection<Double> list)
Converts a collection (List, Set...) of Double objects to a double array.
Parameters:
list - Input list
Returns:
int array
• #### toArray

public static double[] toArray(String[] list)
Converts an array of String with the values, into a double array. Uses Double.parseDouble to parse the number, an can raise the exceptions that this method raises
Parameters:
list - Input list
Returns:
output array
• #### toIntArray

public static int[] toIntArray(double[] array)
Converts a double array to an int array
Parameters:
array - Input array
Returns:
int array
• #### toList

public static List<Double> toList(double[] array)
Converts from a double array to a list.
Parameters:
array - Input array
Returns:
A list of Double objects
• #### toString

public static String toString(double[] array)
Converts the array into an String of space separated values. If the array is empty, "" is returned
Parameters:
array - Input array
Returns:
The string representation
• #### union

public static double[] union(double[]... arrays)
Returns an array with all elements in input arrays (no repetitions). There is no order guarantee.
Parameters:
arrays - Input arrays
Returns:
A new array with all elements in input arrays
• #### unique

public static double[] unique(double[] array)
Returns the same values of the input array but with no repetitions. There is no order guarantee.
Parameters:
array - Input array
Returns:
Same values as in array but with no repetitions
• #### zeros

public static double[] zeros(int N)
Returns an array filled with zeros.
Parameters:
N - Number of elements
Returns:
An all-zero array of length N
• #### zeros

public static <A> Map<A,Double> zeros(Set<A> identifiers)
Returns a map filled with zeros.
Type Parameters:
A - Key type
Parameters:
identifiers - Set of unique identifiers keys
Returns:
An all-zero map