Go to the documentation of this file.00001
00007 #include <vl/kmeans.h>
00008 #include <vl/host.h>
00009 #include <vl/kdtree.h>
00010
00011
00012
00013 int main(int argc VL_UNUSED, char ** argv VL_UNUSED)
00014 {
00015 VlRand rand ;
00016
00017 vl_size numData = 100000;
00018 vl_size dimension = 256;
00019 vl_size numCenters = 400;
00020 vl_size maxiter = 10;
00021 vl_size maxComp = 100;
00022 vl_size maxrep = 1;
00023 vl_size ntrees = 1;
00024
00025 double * data;
00026
00027 vl_size dataIdx, d;
00028
00029
00030 VlKMeansAlgorithm algorithm = VlKMeansLloyd ;
00031
00032 VlVectorComparisonType distance = VlDistanceL2 ;
00033 VlKMeans * kmeans = vl_kmeans_new (VL_TYPE_DOUBLE,distance) ;
00034
00035 vl_rand_init (&rand) ;
00036 vl_rand_seed (&rand, 1000) ;
00037
00038 data = vl_malloc(sizeof(double) * dimension * numData);
00039
00040 for(dataIdx = 0; dataIdx < numData; dataIdx++) {
00041 for(d = 0; d < dimension; d++) {
00042 double randomNum = (double)vl_rand_real3(&rand)+1;
00043 data[dataIdx*dimension+d] = randomNum;
00044 }
00045 }
00046
00047 vl_kmeans_set_verbosity (kmeans,1);
00048 vl_kmeans_set_max_num_iterations (kmeans, maxiter) ;
00049 vl_kmeans_set_max_num_comparisons (kmeans, maxComp) ;
00050 vl_kmeans_set_num_repetitions (kmeans, maxrep) ;
00051 vl_kmeans_set_num_trees (kmeans, ntrees);
00052 vl_kmeans_set_algorithm (kmeans, algorithm);
00053
00054
00055
00056
00057 vl_kmeans_cluster(kmeans,data,dimension,numData,numCenters);
00058
00059
00060
00061
00062
00063 vl_kmeans_delete(kmeans);
00064 vl_free(data);
00065
00066 return 0 ;
00067 }