GPUMLib  0.2.2
GPU Machine Learning Library
Macros | Functions
KMeans Clustering kernels

Macros

#define imax(X, Y)   ((X) > (Y) ? (X) : (Y))
 
#define imin(X, Y)   ((X) < (Y) ? (X) : (Y))
 
#define round(x)   (x<0?ceil((x)-0.5):floor((x)+0.5))
 

Functions

void KernelEuclidianDistance (cudafloat *d_C, cudafloat *d_A, cudafloat *d_B, int uiWA, int uiWB, int uiWC, int uiHC)
 
void KernelCenterAttribution (cudafloat *Output, int output_height, int output_width, int *attrib_center)
 
void KernelPrepareCenterCopy (cudafloat *Output, int output_height, int output_width, int *attrib_center)
 
void KernelCopyCenters (cudafloat *Output, int output_height, int output_width, cudafloat *Input, int input_height, int *attrib_center, cudafloat *Indexes, int idx_height, int idx_width)
 
void KernelReduce2 (int *output, int *input, int *g_idata_old, int n)
 
void KernelCenterAttribution_Bounds (cudafloat *Output, int output_height, int output_width, int *attrib_center, float *upperbound)
 
void KernelCopyCenters2 (cudafloat *Output, int output_height, int output_width, cudafloat *Input, int input_width, int *attrib_center)
 
void KernelS (cudafloat *Output, int output_height, int output_width, float *S)
 
void KernelStep3 (float *Input, int input_height, float *Upperbounds, float *S, bool *R, int *CenterAttrib, float *LowerBounds, float *DistanceBeetweenCenters, float *InitialDistances, float *NewCenters, int centers_height, int centers_width)
 
void KernelReduce_bool (bool *output, bool *input, int n)
 
void KernelStep5 (int input_height, float *Upperbounds, bool *R, int *CenterAttrib, float *LowerBounds, float *DistanceBeetweenCenters, float *InitialDistances, float *NewCenters, int centers_height, int centers_width)
 
unsigned int nextPow2 (unsigned int x)
 

Detailed Description

Function Documentation

void KernelCenterAttribution ( cudafloat Output,
int  output_height,
int  output_width,
int *  attrib_center 
)

Kernel that attributes each sample of the training data to one cluster. Given a distance matrix, it finds the minimum distance and stores the obtained cluster number in the attribution array.

Parameters
[in]OutputDistance matrix, each row has the distance between a row in the training data and cluster represented by each column.
[in]output_heightHeight of the distance matrix (number of training samples).
[in]output_widthWidth of the distance matrix (number of clusters).
[out]attrib_centerOutput array with an entry for each sample in the training data with the attributed cluster.

Definition at line 175 of file KMeansKernels.cu.

void KernelCenterAttribution_Bounds ( cudafloat Output,
int  output_height,
int  output_width,
int *  attrib_center,
float *  upperbound 
)

Kernel that attributes each sample of the training data to one cluster, and updates the upperbounds. Given a distance matrix, it finds the minimum distance and stores the obtained cluster number in the attribution array.

Parameters
[in]OutputDistance matrix, each row has the distance between a row in the training data and cluster represented by each column.
[in]output_heightHeight of the distance matrix (number of training samples).
[in]output_widthWidth of the distance matrix (number of clusters).
[out]attrib_centerOutput array with an entry for each sample in the training data with the attributed cluster.
[out]upperboundArray with the upperbounds for each sample.

Definition at line 491 of file KMeansKernels.cu.

void KernelCopyCenters ( cudafloat Output,
int  output_height,
int  output_width,
cudafloat Input,
int  input_height,
int *  attrib_center,
cudafloat Indexes,
int  idx_height,
int  idx_width 
)

Kernel that averages all the training samples attributed to a cluster, and stores the result as the new cluster centroid.

Parameters
[out]OutputMatrix with the new centroids for all clusters.
[in]output_heightHeight of the centroid matrix (number of clusters).
[in]output_widthWidth of the centroid matrix (number of features).
[out]InputMatrix with the indexes of the samples to average for each cluster.
[in]input_heightHeight of the index copy matrix.
[in]attrib_centerArray with an entry for each sample in the training data with the attributed cluster.
[in]Indexesindexes.
[in]idx_heightindex height.
[in]idx_widthindex width.

Definition at line 294 of file KMeansKernels.cu.

void KernelCopyCenters2 ( cudafloat Output,
int  output_height,
int  output_width,
cudafloat Input,
int  input_width,
int *  attrib_center 
)

Kernel that averages all the training samples attributed to a cluster, and stores the result as the new cluster centroid.

Parameters
[out]OutputMatrix with the new centroids for all clusters.
[in]output_heightHeight of the centroid matrix (number of clusters).
[in]output_widthWidth of the centroid matrix (number of features).
[in]InputMatrix with the training samples to average.
[in]input_widthHeight of the training matrix.
[in]attrib_centerArray with an entry for each sample in the training data with the attributed cluster.

Definition at line 534 of file KMeansKernels.cu.

void KernelEuclidianDistance ( cudafloat d_C,
cudafloat d_A,
cudafloat d_B,
int  uiWA,
int  uiWB,
int  uiWC,
int  uiHC 
)

Kernel that calculates the distance between all rows of matrix A in relation to all rows of matrix B, the result is stored in matrix C. Index (i,j) in matrix C is equivalent to the distance between row i in matrix A and row j in matrix B.

Parameters
[out]d_CFinal matrix with the calculated distances.
[in]d_AMatrix A.
[in]d_BMatrix B.
[in]uiWAWidth of matrix A.
[in]uiWBWidth of matrix B.
[in]uiWCWidth of matrix C.
[in]uiHCHeight of matrix C.

Definition at line 135 of file KMeansKernels.cu.

void KernelPrepareCenterCopy ( cudafloat Output,
int  output_height,
int  output_width,
int *  attrib_center 
)

Kernel that given an array with the attributed clusters for each training sample, stores the indexes of each sample in the output matrix in the corresponding column to its attributed cluster.

Parameters
[out]OutputMatrix with the indexes of the samples to average for each cluster.
[in]output_heightHeight of the index copy matrix (number of training samples).
[in]output_widthWidth of the index copy matrix (number of clusters).
[in]attrib_centerArray with an entry for each sample in the training data with the attributed cluster.

Definition at line 238 of file KMeansKernels.cu.

void KernelReduce2 ( int *  output,
int *  input,
int *  g_idata_old,
int  n 
)

Kernel that compares two arrays and stores the result.

Parameters
[out]outputArray with the result of the comparation.
[in]inputArray with the attribution of training samples to clusters.
[in]g_idata_oldArray with the old attribution.
[in]nLength of the array (number of training samples)

Definition at line 381 of file KMeansKernels.cu.

void KernelReduce_bool ( bool *  output,
bool *  input,
int  n 
)

Kernel that checks if all values in a given array are true.

Parameters
[out]outputArray with the result of the comparation.
[in]inputArray of booleans, true for changed data.
[in]nLength of the array (number of training samples)

Definition at line 761 of file KMeansKernels.cu.

void KernelS ( cudafloat Output,
int  output_height,
int  output_width,
float *  S 
)

Kernel that updates the S value for each cluster.

Parameters
[in]OutputMatrix with the distances between clusters.
[in]output_heightHeight of the distance matrix
[in]output_widthWidth of the distance matrix.
[out]SArray with the S value for each cluster.

Definition at line 575 of file KMeansKernels.cu.

void KernelStep3 ( float *  Input,
int  input_height,
float *  Upperbounds,
float *  S,
bool *  R,
int *  CenterAttrib,
float *  LowerBounds,
float *  DistanceBeetweenCenters,
float *  InitialDistances,
float *  NewCenters,
int  centers_height,
int  centers_width 
)

Kernel that calculates the distance between the rows of two matrices, applies the triangle inequality property to minimize the number of calculations.

Parameters
[in]InputMatrix with the training data.
[in]input_heightHeight of the training matrix.
[in]UpperboundsArray with the upperbounds for each training sample.
[in]SArray with the S value for each cluster.
[in]RArray of booleans with information if training sample changed its cluster attribution.
[in]CenterAttribArray with the attribution of samples to clusters.
[in]LowerBoundsArray with the lowerbounds for the training samples.
[in]DistanceBeetweenCentersMatrix with the distance between centroids.
[in]InitialDistancesMatrix with distances between training samples and cluster centroids.
[in]NewCentersMatrix with the centroids of the chosen clusters.
[in]centers_heightHeight of the centroid matrix.
[in]centers_widthWidth of the centroid matrix.

Definition at line 662 of file KMeansKernels.cu.

void KernelStep5 ( int  input_height,
float *  Upperbounds,
bool *  R,
int *  CenterAttrib,
float *  LowerBounds,
float *  DistanceBeetweenCenters,
float *  InitialDistances,
float *  NewCenters,
int  centers_height,
int  centers_width 
)

Kernel that updates the upper and lower bounds. Resets R array.

Parameters
[in]input_heightHeight of the training matrix.
[out]UpperboundsArray with the upperbounds for each training sample.
[out]RArray of booleans with information if training sample changed its cluster attribution.
[in]CenterAttribArray with the attribution of samples to clusters.
[out]LowerBoundsArray with the lowerbounds for the training samples.
[in]DistanceBeetweenCentersMatrix with the distance between centroids.
[in]InitialDistancesMatrix with distances between training samples and cluster centroids.
[in]NewCentersMatrix with the centroids of the chosen clusters.
[in]centers_heightHeight of the centroid matrix.
[in]centers_widthWidth of the centroid matrix.

Definition at line 702 of file KMeansKernels.cu.