Java Utililty Methods Vector

List of utility methods to do Vector

Description

The list of methods to do Vector are organized into topic(s).

Method

doublevectorKLDivergence(double v1[], double v2[])
vector KL Divergence
if (v1.length != v2.length)
    return Double.MAX_VALUE;
double kl = 0.0;
for (int i = 0; i < v1.length; i++) {
    kl += v1[i] * Math.log(v1[i] / v2[i]);
return kl;
doublevectorL2Norm(double[] v)
Computes the L2 norm of the given vector.
double norm = 0;
for (double d : v) {
    norm += Math.pow(d, 2);
return Math.sqrt(norm);
double[]vectorLog10(double v1[])
vector Log
double result[] = new double[v1.length];
for (int k = 0; k < v1.length; k++)
    result[k] = Math.log10(v1[k]);
return result;
float[][][]vectorMagnitude4D(float[][][][] vec4D)
vector Magnitude D
int rows = vec4D.length;
int cols = vec4D[0].length;
int slices = vec4D[0][0].length;
int components = vec4D[0][0][0].length;
float[][][] M = new float[rows][cols][slices];
double sum = 0;
for (int i = 0; i < rows; i++)
    for (int j = 0; j < cols; j++)
...
floatvectorSimilarity(float[] wordVector1, float[] wordVector2)
vector Similarity
if (wordVector1 == null || wordVector2 == null) {
    return -1;
float sim = 0;
for (int i = 0; i < wordVector1.length; i++) {
    sim += wordVector1[i] * wordVector2[i];
return sim;
...
intvectorSizeToBucketNum(int vectorSize)
vector Size To Bucket Num
return ((vectorSize - 1) >>> 4) + 1;
booleanvectorSubset(Vector aV1, Vector aV2)
Determines if one Vector is a subset of another Vector.
Enumeration v1Enum = aV1.elements();
while (v1Enum.hasMoreElements()) {
    if (!aV2.contains(v1Enum.nextElement())) {
        return false;
return true;
doublevectorValue(double[] x)
vector Value
double v = 0.0;
for (int i = 0; i < x.length; i++) {
    v += (x[i] * x[i]);
return Math.sqrt(v);