public class VectorTools
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.text.FieldPosition |
fp |
static java.text.NumberFormat |
myFormat |
private static java.lang.String |
SPACING |
Constructor and Description |
---|
VectorTools() |
Modifier and Type | Method and Description |
---|---|
static double[] |
add(double[] a,
double[] b) |
static int[] |
add(int[] a,
int[] b) |
static int |
calculateArrayOverlaps(int[] array1,
int[] array2) |
static int[] |
computeDefaultSize(int numInstances) |
static int[] |
computeDefaultSize(int numInstances,
int elementsPerUnit) |
static boolean[] |
createBooleanArray(int dim,
boolean initialValue) |
static Point3d |
crossProduct(Point3d a,
Point3d b)
Calculate the cross product of two 3-dimensional direction vectors.
|
static void |
divByMax(cern.colt.matrix.DoubleMatrix2D matrix) |
static double[][][] |
divide(double[][][] data,
double factor) |
static double[] |
divide(double[] a,
double b) |
static boolean |
equals(double[][] distanceMatrix,
double[][] distanceMatrixFromFile) |
static double[] |
findMiddle(double[] a,
double[] b) |
static double[] |
generateOneVector(int dim) |
static cern.colt.matrix.DoubleMatrix1D |
generateRandomDoubleMatrix1D(int dim) |
static cern.colt.matrix.DoubleMatrix1D |
generateRandomDoubleMatrix1D(int dim,
boolean generateNegativeNumbers) |
static cern.colt.matrix.DoubleMatrix1D |
generateRandomDoubleMatrix1D(java.util.Random rand,
int dim,
boolean generateNegativeNumbers) |
static double[] |
generateRandomVector(int dim)
Generates a random double[] with the given dimensionality, using a new random number generator.
|
static double[] |
generateRandomVector(int dim,
boolean generateNegativeNumbers)
Generates a random double[] with the given dimensionality, using a new random number generator.
|
static double[] |
generateRandomVector(java.util.Random rand,
int dim)
Generates a random double[] with the given dimensionality, using the given random number generator.
|
static double[] |
generateRandomVector(java.util.Random rand,
int dim,
boolean generateNegativeNumbers)
Generates a random double[] with the given dimensionality, using the given random number generator.
|
static double[] |
generateVectorWithValue(int dim,
int value) |
static int |
getIndexOfMaxValue(double... array)
Deprecated.
not used anymore, marked for removal
|
static int |
getIndexOfMaxValue(int... array)
Gets the index of the max value in an array.
|
private static int |
getIndexOfValue(double[] array,
double d,
int skip)
get the index of a given value in an array and skip the given number of indices to avoid duplicate indices in the
results, i.e.
|
private static int |
getIndexOfValue(int[] array,
int d)
get the index of a given value in an array
|
static int[] |
getIndicesOfMaxValues(double[] array,
double threshold)
get the indices of the numberOfIndices largest values in an array
|
static int[] |
getIndicesOfMaxValues(double[] array,
int numberOfIndices)
get the max indices of the numberOfIndices largest values in an array
|
static int[] |
getIndicesOfMaxValues(int[] array,
int numberOfIndices)
get the max indices of the numberOfIndices largest values in an array
|
static int[] |
getIndicesOfMaxValuesOLD(int[] array,
int numberOfIndices)
Deprecated.
FIXME this is not working marked for removal
|
static int |
getMaxValue(int... array)
Gets the index of the max value in an array.
|
static int |
getNumIndicesLargerThanThreshold(double[] array,
double threshold)
return the indices of all values larger than the given threshold
|
static java.lang.String |
getSpaces(int n) |
static boolean |
isNullVector(double... vector) |
static boolean |
isNullVector(int... vector) |
static void |
main(java.lang.String[] args)
main method for testing purposes only.
|
static double[] |
meanVector(double[][] a)
Calculates the mean vector from the given array of vectors.
|
static double |
median(double... values)
Calculates the median of a vector.
|
static double[] |
medianVector(double[][] a) |
static int[] |
mergeArrays(int[] directions1,
int[] directions2)
merges two direction arrays, i.e.
|
static double[][][] |
multiply(double[][][] data,
double factor) |
static double[] |
multiply(double[][] matrix,
double[] vec) |
static double[] |
multiply(double[] a,
double b) |
static double[] |
multiply(double[] a,
double[] b) |
static double[] |
multiply(double[] vec,
double[][] matrix) |
static void |
normalise(cern.colt.matrix.DoubleMatrix2D matrix)
Normalises a matrix.
|
static double[] |
normaliseByLength(double... vector)
Normalises vector elements by the length of the vector, i.e.
|
static double[] |
normaliseByLength(double[] vector,
double length) |
static InputDatum |
normaliseByLength(InputDatum datum) |
static InputDatum |
normaliseByLength(InputDatum datum,
double length) |
static double[] |
normaliseVectorToUnitLength(double... vector)
Calculates vector normalised to unit length.
|
static java.lang.String |
printMatrix(double[][] matrix) |
static java.lang.String |
printMatrix(double[][] m,
int d,
int w)
Method for printing a double float matrix
Based on ER Harold, "Java I/O", O'Reilly, around p. |
static java.lang.String |
printMatrix(int[][] matrix) |
static java.lang.String |
printMatrix(java.lang.Object[][] matrix) |
static java.lang.String |
printMatrixComparison(double[][] matrix,
double[][] otherMatrix) |
static java.lang.String |
printVect(double[] m,
int d,
int w)
Method printVect for printing a double float vector
Based on ER Harold, "Java I/O", O'Reilly, around p. |
static java.lang.StringBuffer |
printVector(double... vector) |
static java.lang.StringBuffer |
printVector(int... vector) |
static java.lang.StringBuffer |
printVector(int[] vector,
java.lang.String spacing) |
static java.lang.StringBuffer |
printVector(java.lang.Object... vector) |
static java.lang.StringBuffer |
printVector(java.lang.Object[] vector,
java.lang.String spacing) |
static double[] |
removeIndex(double[] array,
int indexToRemove)
Deprecated.
use
ArrayUtils.remove(double[], int) instead |
static int[] |
removeIndex(int[] array,
int indexToRemove)
Remove an index from an array, it's as simple as that.
|
static java.util.HashMap<java.lang.Object,java.lang.Integer> |
reverseHashMap(java.util.Map<java.lang.Integer,java.lang.Object> map)
Creates a
Map with an inversed mapping of the original map, i.e. |
static double[] |
slice(double[][] array,
int i) |
static double |
standard_deviation(double... a) |
static double[] |
subtract(double[] a,
double[] b) |
static int[] |
subtract(int[] a,
int[] b) |
static int |
sum(int... array) |
static double[][] |
transpose(double[][] matrix) |
static double |
vectorLength(double... vector) |
private static final java.lang.String SPACING
public static final java.text.NumberFormat myFormat
private static final java.text.FieldPosition fp
public static double[] subtract(double[] a, double[] b)
public static int[] subtract(int[] a, int[] b)
public static double[] add(double[] a, double[] b)
public static int[] add(int[] a, int[] b)
public static double[] multiply(double[] a, double[] b) throws MetricException
MetricException
public static double[] multiply(double[] a, double b)
public static double[] divide(double[] a, double b)
public static double[] generateRandomVector(int dim)
dim
- the dimensionality of the double[]public static double[] generateRandomVector(java.util.Random rand, int dim)
rand
- a random number generatordim
- the dimensionality of the double[]public static double[] generateRandomVector(int dim, boolean generateNegativeNumbers)
dim
- the dimensionality of the double[]generateNegativeNumbers
- whether to generate negative numbers or not.public static double[] generateRandomVector(java.util.Random rand, int dim, boolean generateNegativeNumbers)
rand
- a random number generatordim
- the dimensionality of the double[]generateNegativeNumbers
- whether to generate negative numbers or not.public static cern.colt.matrix.DoubleMatrix1D generateRandomDoubleMatrix1D(java.util.Random rand, int dim, boolean generateNegativeNumbers)
public static cern.colt.matrix.DoubleMatrix1D generateRandomDoubleMatrix1D(int dim, boolean generateNegativeNumbers)
public static cern.colt.matrix.DoubleMatrix1D generateRandomDoubleMatrix1D(int dim)
public static void normalise(cern.colt.matrix.DoubleMatrix2D matrix)
matrix
- the matrix to normalise.public static void divByMax(cern.colt.matrix.DoubleMatrix2D matrix)
public static double[] normaliseByLength(double... vector)
public static double vectorLength(double... vector)
public static double[] normaliseByLength(double[] vector, double length)
public static InputDatum normaliseByLength(InputDatum datum)
public static InputDatum normaliseByLength(InputDatum datum, double length)
public static double median(double... values)
values
- the vector elementspublic static double standard_deviation(double... a)
a
- an arraypublic static boolean[] createBooleanArray(int dim, boolean initialValue)
public static java.util.HashMap<java.lang.Object,java.lang.Integer> reverseHashMap(java.util.Map<java.lang.Integer,java.lang.Object> map)
Map
with an inversed mapping of the original map, i.e. a valu e-> key mapping.public static double[] meanVector(double[][] a)
public static double[] medianVector(double[][] a)
public static java.lang.String printMatrix(double[][] matrix)
public static java.lang.String printMatrix(java.lang.Object[][] matrix)
public static java.lang.String printMatrix(int[][] matrix)
public static java.lang.String printMatrix(double[][] m, int d, int w)
m
- input matrix values, doubled
- display precision, number of decimal placesw
- display precision, total width of floating valuepublic static java.lang.String printVect(double[] m, int d, int w)
m
- input vector of length m.lengthd
- display precision, number of decimal placesw
- display precision, total width of floating valuepublic static java.lang.String getSpaces(int n)
public static java.lang.StringBuffer printVector(double... vector)
public static java.lang.StringBuffer printVector(int... vector)
public static java.lang.StringBuffer printVector(int[] vector, java.lang.String spacing)
public static java.lang.StringBuffer printVector(java.lang.Object... vector)
public static java.lang.StringBuffer printVector(java.lang.Object[] vector, java.lang.String spacing)
public static java.lang.String printMatrixComparison(double[][] matrix, double[][] otherMatrix)
public static boolean equals(double[][] distanceMatrix, double[][] distanceMatrixFromFile)
public static double[] generateOneVector(int dim)
public static double[] generateVectorWithValue(int dim, int value)
public static double[][] transpose(double[][] matrix)
public static void main(java.lang.String[] args)
public static double[] multiply(double[][] matrix, double[] vec)
public static double[] multiply(double[] vec, double[][] matrix)
public static int getIndexOfMaxValue(int... array)
array
- the input arraypublic static int getMaxValue(int... array)
array
- the input array@Deprecated public static int getIndexOfMaxValue(double... array)
array
- the input arraypublic static int[] getIndicesOfMaxValues(double[] array, int numberOfIndices)
array
- the input arraynumberOfIndices
- the desired number of indices to get in returnpublic static int[] getIndicesOfMaxValues(int[] array, int numberOfIndices)
array
- the input arraynumberOfIndices
- how manypublic static int[] getIndicesOfMaxValues(double[] array, double threshold)
array
- inputthreshold
- value to compare topublic static int getNumIndicesLargerThanThreshold(double[] array, double threshold)
array
- inputthreshold
- to compare toprivate static int getIndexOfValue(double[] array, double d, int skip)
array
- the input arrayd
- the value to search forprivate static int getIndexOfValue(int[] array, int d)
array
- the input arrayd
- the value to search for@Deprecated public static int[] getIndicesOfMaxValuesOLD(int[] array, int numberOfIndices)
array
- an array of doublesnumberOfIndices
- the number of max values you want the indices of@Deprecated public static double[] removeIndex(double[] array, int indexToRemove)
ArrayUtils.remove(double[], int)
insteadarray
- the input arrayindexToRemove
- the index to removepublic static int[] removeIndex(int[] array, int indexToRemove)
array
- the input arrayindexToRemove
- index to removepublic static int sum(int... array)
public static int calculateArrayOverlaps(int[] array1, int[] array2)
public static int[] mergeArrays(int[] directions1, int[] directions2)
directions1
- direction onedirections2
- direction twopublic static double[][][] multiply(double[][][] data, double factor)
public static double[][][] divide(double[][][] data, double factor)
public static boolean isNullVector(double... vector)
public static boolean isNullVector(int... vector)
public static double[] normaliseVectorToUnitLength(double... vector)
vector
- Vector to be normalisedpublic static Point3d crossProduct(Point3d a, Point3d b)
a
- first direction vectorb
- second direction vectorpublic static int[] computeDefaultSize(int numInstances)
public static int[] computeDefaultSize(int numInstances, int elementsPerUnit)
public static double[] slice(double[][] array, int i)
public static double[] findMiddle(double[] a, double[] b)