|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectat.tuwien.ifs.somtoolbox.util.VectorTools
public class VectorTools
This class provides several utility methods to operate on Vectors.
Field Summary | |
---|---|
private static FieldPosition |
fp
|
static NumberFormat |
myFormat
|
private static String |
SPACING
|
Constructor Summary | |
---|---|
VectorTools()
|
Method Summary | |
---|---|
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(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(Random rand,
int dim)
Generates a random double[] with the given dimensionality, using the given random number generator. |
static double[] |
generateRandomVector(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 String |
getSpaces(int n)
|
static boolean |
isNullVector(double... vector)
|
static boolean |
isNullVector(int... vector)
|
static void |
main(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 String |
printMatrix(double[][] matrix)
|
static 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 String |
printMatrix(int[][] matrix)
|
static String |
printMatrix(Object[][] matrix)
|
static String |
printMatrixComparison(double[][] matrix,
double[][] otherMatrix)
|
static 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 StringBuffer |
printVector(double... vector)
|
static StringBuffer |
printVector(int... vector)
|
static StringBuffer |
printVector(int[] vector,
String spacing)
|
static StringBuffer |
printVector(Object... vector)
|
static StringBuffer |
printVector(Object[] vector,
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 HashMap<Object,Integer> |
reverseHashMap(Map<Integer,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)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String SPACING
public static final NumberFormat myFormat
private static final FieldPosition fp
Constructor Detail |
---|
public VectorTools()
Method Detail |
---|
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(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(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(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 elements
public static double standard_deviation(double... a)
a
- an array
public static boolean[] createBooleanArray(int dim, boolean initialValue)
public static HashMap<Object,Integer> reverseHashMap(Map<Integer,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 String printMatrix(double[][] matrix)
public static String printMatrix(Object[][] matrix)
public static String printMatrix(int[][] matrix)
public static 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 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 String getSpaces(int n)
public static StringBuffer printVector(double... vector)
public static StringBuffer printVector(int... vector)
public static StringBuffer printVector(int[] vector, String spacing)
public static StringBuffer printVector(Object... vector)
public static StringBuffer printVector(Object[] vector, String spacing)
public static 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(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 array
public static int getMaxValue(int... array)
array
- the input array
@Deprecated public static int getIndexOfMaxValue(double... array)
array
- the input array
public static int[] getIndicesOfMaxValues(double[] array, int numberOfIndices)
array
- the input arraynumberOfIndices
- the desired number of indices to get in return
public static int[] getIndicesOfMaxValues(int[] array, int numberOfIndices)
array
- the input arraynumberOfIndices
- how many
public static int[] getIndicesOfMaxValues(double[] array, double threshold)
array
- inputthreshold
- value to compare to
public static int getNumIndicesLargerThanThreshold(double[] array, double threshold)
array
- inputthreshold
- to compare to
private static int getIndexOfValue(double[] array, double d, int skip)
array
- the input arrayd
- the value to search for
private 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)
instead
array
- the input arrayindexToRemove
- the index to remove
public static int[] removeIndex(int[] array, int indexToRemove)
array
- the input arrayindexToRemove
- index to remove
public 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 two
public 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 normalised
public static Point3d crossProduct(Point3d a, Point3d b)
a
- first direction vectorb
- second direction vector
public 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)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |