public final class Vectors
extends java.lang.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 |
dotProduct(Long2DoubleSortedArrayMap v1,
Long2DoubleSortedArrayMap v2)
Compute the dot product of two maps (optimized).
|
static double |
euclideanNorm(Long2DoubleMap v)
Compute the Euclidean norm of the values of the map.
|
static java.lang.Iterable<Long2DoubleMap.Entry> |
fastEntries(Long2DoubleMap map) |
static java.util.Iterator<Long2DoubleMap.Entry> |
fastEntryIterator(Long2DoubleMap map)
Get an iterator over the entries of the map.
|
static org.apache.commons.math3.linear.RealVector |
matrixRow(org.apache.commons.math3.linear.RealMatrix mat,
int row)
Create a flyweight row view of a matrix.
|
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 double |
sumOfSquares(Long2DoubleSortedArrayMap v)
Compute the sum of the squares of elements of a map (optimized).
|
static Long2DoubleMap |
transform(Long2DoubleMap input,
java.util.function.DoubleUnaryOperator function)
Transform the values of a vector.
|
static Long2DoubleMap |
unitVector(Long2DoubleMap v)
Convert a vector to a unit vector.
|
public static java.util.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 java.lang.Iterable<Long2DoubleMap.Entry> fastEntries(Long2DoubleMap 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 sumOfSquares(Long2DoubleSortedArrayMap v)
Compute the sum of the squares of elements of a map (optimized).
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 Long2DoubleMap unitVector(Long2DoubleMap v)
Convert a vector to a unit vector.
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 dotProduct(Long2DoubleSortedArrayMap v1, Long2DoubleSortedArrayMap v2)
Compute the dot product of two maps (optimized). 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, java.util.function.DoubleUnaryOperator function)
Transform the values of a vector.
input
- The vector to transform.function
- The transformation to apply.function
to each value in input
.public static org.apache.commons.math3.linear.RealVector matrixRow(org.apache.commons.math3.linear.RealMatrix mat, int row)
Create a flyweight row view of a matrix.
mat
- The matrix.row
- The row number.