Class Utils
java.lang.Object
de.unijena.cheminf.clustering.art2a.Utils
Library of helper records, static helper classes and static, thread-safe
(stateless) utility methods for ART-2a and ART-2a-Euclid clustering.
Note: No checks are performed.
Note: No checks are performed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classHelper class: Cluster removal info.protected static final recordHelper record: Minimum and maximum value.protected static classHelper class: Rho winner. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidcopyMatrix(float[][] aSourceMatrix, float[][] aDestinationMatrix) (Deep) Copies source matrix to destination matrix.protected static voidcopyRows(float[][] aSourceMatrix, float[][] aDestinationMatrix, int aNumberOfRows) (Deep) Copies specified number of rows of source matrix to destination matrix.protected static voidcopyVector(float[] aSourceVector, float[] aDestinationVector) (Deep) Copies source vector to destination vector.protected static voidenhanceContrast(float[] aVector, float aThresholdForContrastEnhancement) Calculates contrast enhanced vector.protected static voidfillMatrix(float[][] aMatrix, float aValue) Fills matrix with value.protected static voidfillVector(boolean[] aVector, boolean aValue) Fills vector with value.protected static voidfillVector(float[] aVector, float aValue) Fills vector with value.protected static voidfillVector(int[] aVector, int aValue) Fills vector with value.protected static floatgetMeanDistance(float[][] aMatrix, int[] anIndicesOfRowVectors) Returns mean distance of all specified row vectors.protected static Utils.MinMaxValue[]getMinMaxComponents(float[][] aMatrix) Returns min-max components for matrix where MinMaxValue[j] corresponds to column j of the row vectors of the matrix.protected static floatgetScalarProduct(float[] aVector1, float[] aVector2) Calculates the scalar product (dot product) of aVector1 and aVector2.protected static float[]getScaledVector(float[] aVectorToBeScaled) Scales components of aVectorToBeScaled to interval [0,1].protected static floatgetSquaredDistance(float[] aVector1, float[] aVector2) Calculates the squared distance between aVector1 and aVector2.protected static floatgetSumOfComponents(float[] aVector) Calculates the sum of components of aVector.protected static floatgetSumOfSquaredDifferences(float[] aVector, float aValue) Calculates the sum of squared differences between the components of the specified vector and a value.protected static floatgetThresholdForContrastEnhancement(int aNumberOfComponents, float anOffsetForContrastEnhancement) Threshold for contrast enhancementprotected static int[][]getTrainingAndTestIndices(Art2aResult anArt2aResult) Creates clustering-based training and test data vector indices that cover a similar space.protected static floatgetVectorLength(float[] aVector) Calculates the length of aVector.protected static booleanhasLengthOfZero(float[] aVector) Checks if vector has a length of zero (i.e.protected static booleanhasNonFiniteComponent(float[][] aDataMatrix) Checks if data matrix has a non-finite component.protected static booleanisContrastEnhanced(float[] aVector, float aThresholdForContrastEnhancement) Calculates contrast enhanced vector.static booleanisDataMatrixValid(float[][] aDataMatrix) Checks if aDataMatrix is valid.protected static booleanisMatrixValid(float[][] aMatrix) Checks if matrix is valid.static booleanisNonFiniteComponentRemoval(float[][] aDataMatrix) Removes columns from data matrix with non-finite components.protected static voidnormalizeVector(float[] aVector) Calculates normalized (unit) vector of length 1.protected static voidremoveEmptyClusters(boolean[] aClusterUsageFlags, float[][] aClusterMatrix, int aNumberOfDetectedClusters, Utils.ClusterRemovalInfo aClusterRemovalInfo) Removes empty clusters from cluster matrixprotected static voidscaleVector(float[] aVectorToBeScaled, Utils.MinMaxValue[] aMinMaxComponents) Scales components of aVectorToBeScaled according to min-max components to interval [0,1] (see code and method getMinMaxComponents()).protected static voidsetContrastEnhancement(float[] aVector, float aThresholdForContrastEnhancement) Calculates contrast enhanced vector.protected static voidsetRowVector(float[][] aMatrix, float[] aRowVector, int anIndex) Sets copied (!) row vector at index in matrix.protected static voidshuffleIndices(int[] anIndexArray, Random aRandomNumberGenerator) Randomly shuffles indices from 0 to (anIndices.Length - 1) in anIndexArray using Fisher-Yates shuffling (i.e.
-
Constructor Details
-
Utils
protected Utils()Constructor
-
-
Method Details
-
isDataMatrixValid
public static boolean isDataMatrixValid(float[][] aDataMatrix) Checks if aDataMatrix is valid.- Parameters:
aDataMatrix- Data matrix with data row vectors (IS NOT CHANGED)- Returns:
- True if aDataMatrix is valid, false otherwise.
-
isNonFiniteComponentRemoval
public static boolean isNonFiniteComponentRemoval(float[][] aDataMatrix) Removes columns from data matrix with non-finite components. Note: If aDataMatrix is null, empty or has an invalid structure nothing is done and false is returned.- Parameters:
aDataMatrix- Data matrix with data row vectors (MAY BE CHANGED)- Returns:
- True if aDataMatrix was changed (i.e. column removal was performed), false otherwise (i.e. data matrix is unchanged).
-
copyMatrix
protected static void copyMatrix(float[][] aSourceMatrix, float[][] aDestinationMatrix) (Deep) Copies source matrix to destination matrix. Row vectors of destination matrix may not have been instantiated.- Parameters:
aSourceMatrix- Source matrix (IS NOT CHANGED)aDestinationMatrix- Destination matrix (MUST HAVE BEEN INSTANTIATED and MAY BE CHANGED)
-
copyRows
protected static void copyRows(float[][] aSourceMatrix, float[][] aDestinationMatrix, int aNumberOfRows) (Deep) Copies specified number of rows of source matrix to destination matrix. Row vectors of destination matrix may not have been instantiated.- Parameters:
aSourceMatrix- Source matrix (IS NOT CHANGED)aDestinationMatrix- Destination matrix (MUST HAVE BEEN INSTANTIATED and MAY BE CHANGED)aNumberOfRows- Number of rows to be copied from source matrix to destination matrix
-
copyVector
protected static void copyVector(float[] aSourceVector, float[] aDestinationVector) (Deep) Copies source vector to destination vector.- Parameters:
aSourceVector- Source vector (IS NOT CHANGED)aDestinationVector- Destination vector (MUST HAVE BEEN INSTANTIATED and MAY BE CHANGED)
-
enhanceContrast
protected static void enhanceContrast(float[] aVector, float aThresholdForContrastEnhancement) Calculates contrast enhanced vector.- Parameters:
aVector- Vector to be contrast enhanced (MAY BE CHANGED)aThresholdForContrastEnhancement- Threshold for contrast enhancement
-
fillMatrix
protected static void fillMatrix(float[][] aMatrix, float aValue) Fills matrix with value.- Parameters:
aMatrix- Matrix (MAY BE CHANGED)aValue- Value
-
fillVector
protected static void fillVector(float[] aVector, float aValue) Fills vector with value.- Parameters:
aVector- Vector (MAY BE CHANGED)aValue- Value
-
fillVector
protected static void fillVector(boolean[] aVector, boolean aValue) Fills vector with value.- Parameters:
aVector- Vector (MAY BE CHANGED)aValue- Value
-
fillVector
protected static void fillVector(int[] aVector, int aValue) Fills vector with value.- Parameters:
aVector- Vector (MAY BE CHANGED)aValue- Value
-
getMeanDistance
protected static float getMeanDistance(float[][] aMatrix, int[] anIndicesOfRowVectors) Returns mean distance of all specified row vectors.- Parameters:
aMatrix- Matrix with row vectors (IS NOT CHANGED)anIndicesOfRowVectors- Indices of row vectors of aMatrix- Returns:
- Mean squared distance of all specified row vectors.
-
getMinMaxComponents
Returns min-max components for matrix where MinMaxValue[j] corresponds to column j of the row vectors of the matrix. The min-max components may be used to scale row vectors to interval [0,1], see method scaleVector().- Parameters:
aMatrix- Matrix (IS NOT CHANGED)- Returns:
- Min-max components
-
getScalarProduct
protected static float getScalarProduct(float[] aVector1, float[] aVector2) Calculates the scalar product (dot product) of aVector1 and aVector2.- Parameters:
aVector1- Vector 1 (IS NOT CHANGED)aVector2- Vector 2 (IS NOT CHANGED)- Returns:
- Scalar product (dot product)
-
getScaledVector
protected static float[] getScaledVector(float[] aVectorToBeScaled) Scales components of aVectorToBeScaled to interval [0,1].- Parameters:
aVectorToBeScaled- Vector (IS NOT CHANGED)- Returns:
- New scaled vector with components in interval [0,1] or new vector of length zero if all components of aVectorToBeScaled are the same.
-
getSquaredDistance
protected static float getSquaredDistance(float[] aVector1, float[] aVector2) Calculates the squared distance between aVector1 and aVector2.- Parameters:
aVector1- Vector 1 (IS NOT CHANGED)aVector2- Vector 2 (IS NOT CHANGED)- Returns:
- Squared distance
-
getSumOfComponents
protected static float getSumOfComponents(float[] aVector) Calculates the sum of components of aVector.- Parameters:
aVector- Vector (IS NOT CHANGED)- Returns:
- Sum of components
-
getSumOfSquaredDifferences
protected static float getSumOfSquaredDifferences(float[] aVector, float aValue) Calculates the sum of squared differences between the components of the specified vector and a value.- Parameters:
aVector- Vector (IS NOT CHANGED)aValue- Value- Returns:
- Sum of squared differences between the components of the specified vector and a value.
-
getThresholdForContrastEnhancement
protected static float getThresholdForContrastEnhancement(int aNumberOfComponents, float anOffsetForContrastEnhancement) Threshold for contrast enhancement- Parameters:
aNumberOfComponents- Number of componentsanOffsetForContrastEnhancement- Offset for contrast enhancement- Returns:
- Threshold for contrast enhancement
-
getVectorLength
protected static float getVectorLength(float[] aVector) Calculates the length of aVector.- Parameters:
aVector- Vector (IS NOT CHANGED)- Returns:
- Length of vector
-
hasLengthOfZero
protected static boolean hasLengthOfZero(float[] aVector) Checks if vector has a length of zero (i.e. if all components are equal to zero).- Parameters:
aVector- Vector (IS NOT CHANGED)- Returns:
- True: Vector has a length of zero, false: Otherwise
-
hasNonFiniteComponent
protected static boolean hasNonFiniteComponent(float[][] aDataMatrix) Checks if data matrix has a non-finite component. Note: If aDataMatrix is null or empty nothing is done and false is returned.- Parameters:
aDataMatrix- Data matrix with data row vectors (IS NOT CHANGED)- Returns:
- True: Data matrix has non-finite component, false: Otherwise
-
isContrastEnhanced
protected static boolean isContrastEnhanced(float[] aVector, float aThresholdForContrastEnhancement) Calculates contrast enhanced vector.- Parameters:
aVector- Vector to be contrast enhanced (MAY BE CHANGED)aThresholdForContrastEnhancement- Threshold for contrast enhancement- Returns:
- True if aVector is changed by contrast enhancement, false otherwise.
-
isMatrixValid
protected static boolean isMatrixValid(float[][] aMatrix) Checks if matrix is valid.- Parameters:
aMatrix- Matrix- Returns:
- True: Matrix is valid, false: Otherwise
-
normalizeVector
protected static void normalizeVector(float[] aVector) Calculates normalized (unit) vector of length 1.- Parameters:
aVector- Vector to be normalized (MAY BE CHANGED)
-
removeEmptyClusters
protected static void removeEmptyClusters(boolean[] aClusterUsageFlags, float[][] aClusterMatrix, int aNumberOfDetectedClusters, Utils.ClusterRemovalInfo aClusterRemovalInfo) Removes empty clusters from cluster matrix- Parameters:
aClusterUsageFlags- Flags for cluster usage. True: Cluster is used, false: Cluster is empty and has to be removed (IS NOT CHANGED)aClusterMatrix- Cluster matrix (MAY BE CHANGED)aNumberOfDetectedClusters- Number of detected clustersaClusterRemovalInfo- Cluster removal info (is set according to the operations performed, IS CHANGED)
-
scaleVector
Scales components of aVectorToBeScaled according to min-max components to interval [0,1] (see code and method getMinMaxComponents()).- Parameters:
aVectorToBeScaled- Vector to be scaled (MAY BE CHANGED)aMinMaxComponents- Min-max components
-
setContrastEnhancement
protected static void setContrastEnhancement(float[] aVector, float aThresholdForContrastEnhancement) Calculates contrast enhanced vector.- Parameters:
aVector- Vector to be contrast enhanced (MAY BE CHANGED)aThresholdForContrastEnhancement- Threshold for contrast enhancement
-
setRowVector
protected static void setRowVector(float[][] aMatrix, float[] aRowVector, int anIndex) Sets copied (!) row vector at index in matrix.- Parameters:
aMatrix- Matrix (MAY BE CHANGED)aRowVector- Row vector (IS NOT CHANGED)anIndex- Index of row vector in matrix
-
shuffleIndices
Randomly shuffles indices from 0 to (anIndices.Length - 1) in anIndexArray using Fisher-Yates shuffling (i.e. the modern version introduced by Richard Durstenfeld). Note: No checks are performed.- Parameters:
anIndexArray- Array with indices from 0 to (anIndices.Length - 1)aRandomNumberGenerator- Random number generator
-
getTrainingAndTestIndices
Creates clustering-based training and test data vector indices that cover a similar space. The first data vector index of each cluster (which is most similar to the cluster center) is assigned for training, all remaining data vector indices for test. Returns a 2-dimensional jagged integer array where index 0 is the array of training data vector indices and index 1 is the array of test data vector indices. Note: No checks are performed.- Parameters:
anArt2aResult- ART-2a result (IS NOT CHANGED)- Returns:
- 2-dimensional jagged integer array where index 0 is the array of training data vector indices and index 1 is the array of test data vector indices.
-