public final class Vectors extends Object
Utility methods for vector arithmetic.
Modifier and Type | Method and Description |
---|---|
static Long2DoubleMap |
addScalar(Long2DoubleMap vec,
double val)
Add a scalar to each element of a vector.
|
static Long2DoubleMap |
combine(Long2DoubleMap x,
Long2DoubleFunction y,
double sy,
double o)
Add a vector to another (scaled) vector and a scalar.
|
static double |
dotProduct(Long2DoubleMap v1,
Long2DoubleMap v2)
Compute the dot product of two maps.
|
static double |
euclideanNorm(Long2DoubleMap v)
Compute the Euclidean norm of the values of the map.
|
static Iterator<Long2DoubleMap.Entry> |
fastEntryIterator(Long2DoubleMap map)
Get an iterator over the entries of the map.
|
static double |
mean(Long2DoubleMap vec)
Compute the arithmetic mean of a vector’s values.
|
static Long2DoubleMap |
multiplyScalar(Long2DoubleMap vector,
double value)
Multiply each element of a vector by a scalar.
|
static double |
sum(Long2DoubleMap v)
Compute the sum of the elements of a map.
|
static double |
sumAbs(Long2DoubleMap v)
Compute the sum of the elements of a map.
|
static double |
sumOfSquares(Long2DoubleMap v)
Compute the sum of the squares of elements of a map.
|
static Long2DoubleMap |
transform(Long2DoubleMap input,
org.apache.commons.math3.analysis.UnivariateFunction function)
Transform the values of a vector.
|
public static Iterator<Long2DoubleMap.Entry> fastEntryIterator(Long2DoubleMap map)
Get an iterator over the entries of the map. If possible, this is a fast iterator.
map
- The map.public static double sum(Long2DoubleMap v)
Compute the sum of the elements of a map.
v
- The vectorv
.public static double sumAbs(Long2DoubleMap v)
Compute the sum of the elements of a map.
v
- The vectorv
.public static double sumOfSquares(Long2DoubleMap v)
Compute the sum of the squares of elements of a map.
v
- The vectorv
.public static double euclideanNorm(Long2DoubleMap v)
Compute the Euclidean norm of the values of the map. This is the square root of the sum of squares.
v
- The vector.public static double dotProduct(Long2DoubleMap v1, Long2DoubleMap v2)
Compute the dot product of two maps. This method assumes any value missing in one map is 0, so it is the dot product of the values of common keys.
v1
- The first vector.v2
- The second vector.public static double mean(Long2DoubleMap vec)
Compute the arithmetic mean of a vector’s values.
vec
- The vector.public static Long2DoubleMap combine(Long2DoubleMap x, Long2DoubleFunction y, double sy, double o)
Add a vector to another (scaled) vector and a scalar. The result is \(x_i + s_y y_i + o\).
x
- The source vector.y
- The addition vector. Long2DoubleFunction.defaultReturnValue()
is assumed for missing values.sy
- The scale by which elements of y
are multipled.o
- The offset to add.x
, transformed by the specified linear formula.public static Long2DoubleMap addScalar(Long2DoubleMap vec, double val)
Add a scalar to each element of a vector.
vec
- The vector to rescale.val
- The value to add.vec
increased by val
.@Nonnull public static Long2DoubleMap multiplyScalar(Long2DoubleMap vector, double value)
Multiply each element of a vector by a scalar.
vector
- The vector.value
- The scalar to multiply.vector
, with value
multipled by each.public static Long2DoubleMap transform(Long2DoubleMap input, org.apache.commons.math3.analysis.UnivariateFunction function)
Transform the values of a vector.
input
- The vector to transform.function
- The transformation to apply.function
to each value in input
.