kmeans.h
Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00009 Copyright (C) 2013 Andrea Vedaldi and David Novotny.
00010 All rights reserved.
00011 
00012 This file is part of the VLFeat library and is made available under
00013 the terms of the BSD license (see the COPYING file).
00014 */
00015 
00016 #ifndef VL_KMEANS_H
00017 #define VL_KMEANS_H
00018 
00019 #include "generic.h"
00020 #include "random.h"
00021 #include "mathop.h"
00022 #include "kdtree.h"
00023 
00024 /* ---------------------------------------------------------------- */
00025 
00028 typedef enum _VlKMeansAlgorithm {
00029   VlKMeansLloyd,       
00030   VlKMeansElkan,       
00031   VlKMeansANN          
00032 } VlKMeansAlgorithm ;
00033 
00036 typedef enum _VlKMeansInitialization {
00037   VlKMeansRandomSelection,  
00038   VlKMeansPlusPlus          
00039 } VlKMeansInitialization ;
00040 
00045 typedef struct _VlKMeans
00046 {
00047 
00048   vl_type dataType ;                      
00049   vl_size dimension ;                     
00050   vl_size numCenters ;                    
00051   vl_size numTrees ;                      
00052   vl_size maxNumComparisons ;             
00054   VlKMeansInitialization initialization ; 
00055   VlKMeansAlgorithm algorithm ;           
00056   VlVectorComparisonType distance ;       
00057   vl_size maxNumIterations ;              
00058   double minEnergyVariation ;             
00059   vl_size numRepetitions ;                
00060   int verbosity ;                         
00062   void * centers ;                        
00063   void * centerDistances ;                
00065   double energy ;                         
00066   VlFloatVectorComparisonFunction floatVectorComparisonFn ;
00067   VlDoubleVectorComparisonFunction doubleVectorComparisonFn ;
00068 } VlKMeans ;
00069 
00073 VL_EXPORT VlKMeans * vl_kmeans_new (vl_type dataType, VlVectorComparisonType distance) ;
00074 VL_EXPORT VlKMeans * vl_kmeans_new_copy (VlKMeans const * kmeans) ;
00075 VL_EXPORT void vl_kmeans_delete (VlKMeans * self) ;
00081 VL_EXPORT void vl_kmeans_reset (VlKMeans * self) ;
00082 
00083 VL_EXPORT double vl_kmeans_cluster (VlKMeans * self,
00084                                     void const * data,
00085                                     vl_size dimension,
00086                                     vl_size numData,
00087                                     vl_size numCenters) ;
00088 
00089 VL_EXPORT void vl_kmeans_quantize (VlKMeans * self,
00090                                    vl_uint32 * assignments,
00091                                    void * distances,
00092                                    void const * data,
00093                                    vl_size numData) ;
00094 
00095 VL_EXPORT void vl_kmeans_quantize_ANN (VlKMeans * self,
00096                                    vl_uint32 * assignments,
00097                                    void * distances,
00098                                    void const * data,
00099                                    vl_size numData,
00100                                    vl_size iteration );
00106 VL_EXPORT void vl_kmeans_set_centers (VlKMeans * self,
00107                                       void const * centers,
00108                                       vl_size dimension,
00109                                       vl_size numCenters) ;
00110 
00111 VL_EXPORT void vl_kmeans_init_centers_with_rand_data
00112                   (VlKMeans * self,
00113                    void const * data,
00114                    vl_size dimensions,
00115                    vl_size numData,
00116                    vl_size numCenters) ;
00117 
00118 VL_EXPORT void vl_kmeans_init_centers_plus_plus
00119                   (VlKMeans * self,
00120                    void const * data,
00121                    vl_size dimensions,
00122                    vl_size numData,
00123                    vl_size numCenters) ;
00124 
00125 VL_EXPORT double vl_kmeans_refine_centers (VlKMeans * self,
00126                                            void const * data,
00127                                            vl_size numData) ;
00128 
00134 VL_INLINE vl_type vl_kmeans_get_data_type (VlKMeans const * self) ;
00135 VL_INLINE VlVectorComparisonType vl_kmeans_get_distance (VlKMeans const * self) ;
00136 
00137 VL_INLINE VlKMeansAlgorithm vl_kmeans_get_algorithm (VlKMeans const * self) ;
00138 VL_INLINE VlKMeansInitialization vl_kmeans_get_initialization (VlKMeans const * self) ;
00139 VL_INLINE vl_size vl_kmeans_get_num_repetitions (VlKMeans const * self) ;
00140 
00141 VL_INLINE vl_size vl_kmeans_get_dimension (VlKMeans const * self) ;
00142 VL_INLINE vl_size vl_kmeans_get_num_centers (VlKMeans const * self) ;
00143 
00144 VL_INLINE int vl_kmeans_get_verbosity (VlKMeans const * self) ;
00145 VL_INLINE vl_size vl_kmeans_get_max_num_iterations (VlKMeans const * self) ;
00146 VL_INLINE double vl_kmeans_get_min_energy_variation (VlKMeans const * self) ;
00147 VL_INLINE vl_size vl_kmeans_get_max_num_comparisons (VlKMeans const * self) ;
00148 VL_INLINE vl_size vl_kmeans_get_num_trees (VlKMeans const * self) ;
00149 VL_INLINE double vl_kmeans_get_energy (VlKMeans const * self) ;
00150 VL_INLINE void const * vl_kmeans_get_centers (VlKMeans const * self) ;
00156 VL_INLINE void vl_kmeans_set_algorithm (VlKMeans * self, VlKMeansAlgorithm algorithm) ;
00157 VL_INLINE void vl_kmeans_set_initialization (VlKMeans * self, VlKMeansInitialization initialization) ;
00158 VL_INLINE void vl_kmeans_set_num_repetitions (VlKMeans * self, vl_size numRepetitions) ;
00159 VL_INLINE void vl_kmeans_set_max_num_iterations (VlKMeans * self, vl_size maxNumIterations) ;
00160 VL_INLINE void vl_kmeans_set_min_energy_variation (VlKMeans * self, double minEnergyVariation) ;
00161 VL_INLINE void vl_kmeans_set_verbosity (VlKMeans * self, int verbosity) ;
00162 VL_INLINE void vl_kmeans_set_max_num_comparisons (VlKMeans * self, vl_size maxNumComparisons) ;
00163 VL_INLINE void vl_kmeans_set_num_trees (VlKMeans * self, vl_size numTrees) ;
00172 VL_INLINE vl_type
00173 vl_kmeans_get_data_type (VlKMeans const * self)
00174 {
00175   return self->dataType ;
00176 }
00177 
00183 VL_INLINE vl_size
00184 vl_kmeans_get_dimension (VlKMeans const * self)
00185 {
00186   return self->dimension ;
00187 }
00188 
00194 VL_INLINE VlVectorComparisonType
00195 vl_kmeans_get_distance (VlKMeans const * self)
00196 {
00197   return self->distance ;
00198 }
00199 
00205 VL_INLINE vl_size
00206 vl_kmeans_get_num_centers (VlKMeans const * self)
00207 {
00208   return self->numCenters ;
00209 }
00210 
00216 VL_INLINE double
00217 vl_kmeans_get_energy (VlKMeans const * self)
00218 {
00219   return self->energy ;
00220 }
00221 
00228 VL_INLINE int
00229 vl_kmeans_get_verbosity (VlKMeans const * self)
00230 {
00231   return self->verbosity ;
00232 }
00233 
00239 VL_INLINE void
00240 vl_kmeans_set_verbosity (VlKMeans * self, int verbosity)
00241 {
00242   self->verbosity = verbosity ;
00243 }
00244 
00251 VL_INLINE void const *
00252 vl_kmeans_get_centers (VlKMeans const * self)
00253 {
00254   return self->centers ;
00255 }
00256 
00263 VL_INLINE vl_size
00264 vl_kmeans_get_max_num_iterations (VlKMeans const * self)
00265 {
00266   return self->maxNumIterations ;
00267 }
00268 
00274 VL_INLINE void
00275 vl_kmeans_set_max_num_iterations (VlKMeans * self, vl_size maxNumIterations)
00276 {
00277   self->maxNumIterations = maxNumIterations ;
00278 }
00279 
00286 VL_INLINE vl_size
00287 vl_kmeans_get_num_repetitions (VlKMeans const * self)
00288 {
00289   return self->numRepetitions ;
00290 }
00291 
00298 VL_INLINE void
00299 vl_kmeans_set_num_repetitions (VlKMeans * self,
00300                                vl_size numRepetitions)
00301 {
00302   assert (numRepetitions >= 1) ;
00303   self->numRepetitions = numRepetitions ;
00304 }
00305 
00312 VL_INLINE double
00313 vl_kmeans_get_min_energy_variation (VlKMeans const * self)
00314 {
00315   return self->minEnergyVariation ;
00316 }
00317 
00336 VL_INLINE void
00337 vl_kmeans_set_min_energy_variation (VlKMeans * self,
00338                                     double minEnergyVariation)
00339 {
00340   assert (minEnergyVariation >= 0) ;
00341   self->minEnergyVariation = minEnergyVariation ;
00342 }
00343 
00350 VL_INLINE VlKMeansAlgorithm
00351 vl_kmeans_get_algorithm (VlKMeans const * self)
00352 {
00353   return self->algorithm ;
00354 }
00355 
00361 VL_INLINE void
00362 vl_kmeans_set_algorithm (VlKMeans * self, VlKMeansAlgorithm algorithm)
00363 {
00364   self->algorithm = algorithm ;
00365 }
00366 
00373 VL_INLINE VlKMeansInitialization
00374 vl_kmeans_get_initialization (VlKMeans const * self)
00375 {
00376   return self->initialization ;
00377 }
00378 
00384 VL_INLINE void
00385 vl_kmeans_set_initialization (VlKMeans * self,
00386                               VlKMeansInitialization initialization)
00387 {
00388   self->initialization = initialization ;
00389 }
00390 
00397 VL_INLINE vl_size
00398 vl_kmeans_get_max_num_comparisons (VlKMeans const * self)
00399 {
00400   return self->maxNumComparisons ;
00401 }
00402 
00408 VL_INLINE void
00409 vl_kmeans_set_max_num_comparisons (VlKMeans * self,
00410                               vl_size maxNumComparisons)
00411 {
00412     self->maxNumComparisons = maxNumComparisons;
00413 }
00414 
00421 VL_INLINE void
00422 vl_kmeans_set_num_trees (VlKMeans * self, vl_size numTrees)
00423 {
00424     self->numTrees = numTrees;
00425 }
00426 
00427 VL_INLINE vl_size
00428 vl_kmeans_get_num_trees (VlKMeans const * self)
00429 {
00430     return self->numTrees;
00431 }
00432 
00433 
00434 /* VL_IKMEANS_H */
00435 #endif


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51