| 1 |
/** @file ikmeans.h |
| 2 |
** @brief Integer K-Means clustering |
| 3 |
** @author Brian Fulkerson |
| 4 |
** @author Andrea Vedaldi |
| 5 |
**/ |
| 6 |
|
| 7 |
/* |
| 8 |
Copyright (C) 2014 Andrea Vedaldi. |
| 9 |
Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. |
| 10 |
All rights reserved. |
| 11 |
|
| 12 |
This file is part of the VLFeat library and is made available under |
| 13 |
the terms of the BSD license (see the COPYING file). |
| 14 |
*/ |
| 15 |
|
| 16 |
#ifndef VL_IKMEANS_H |
| 17 |
#define VL_IKMEANS_H |
| 18 |
|
| 19 |
#include "generic.h" |
| 20 |
#include "random.h" |
| 21 |
|
| 22 |
#if 0 |
| 23 |
typedef vl_int64 vl_ikmacc_t ; /**< IKM accumulator data type */ |
| 24 |
#define VL_IKMACC_MAX 0x7fffffffffffffffULL |
| 25 |
#else |
| 26 |
typedef vl_int32 vl_ikmacc_t ; /**< IKM accumulator data type */ |
| 27 |
#define VL_IKMACC_MAX 0x7fffffffUL |
| 28 |
#endif |
| 29 |
|
| 30 |
|
| 31 |
/** ------------------------------------------------------------------ |
| 32 |
** @brief IKM algorithms |
| 33 |
**/ |
| 34 |
|
| 35 |
enum VlIKMAlgorithms { |
| 36 |
VL_IKM_LLOYD, /**< Lloyd algorithm */ |
| 37 |
VL_IKM_ELKAN, /**< Elkan algorithm */ |
| 38 |
} ; |
| 39 |
|
| 40 |
/** ------------------------------------------------------------------ |
| 41 |
** @brief IKM quantizer |
| 42 |
**/ |
| 43 |
|
| 44 |
typedef struct _VlIKMFilt |
| 45 |
{ |
| 46 |
vl_size M ; /**< data dimensionality */ |
| 47 |
vl_size K ; /**< number of centers */ |
| 48 |
vl_size max_niters ; /**< Lloyd: maximum number of iterations */ |
| 49 |
int method ; /**< Learning method */ |
| 50 |
int verb ; /**< verbosity level */ |
| 51 |
vl_ikmacc_t *centers ; /**< centers */ |
| 52 |
vl_ikmacc_t *inter_dist ; /**< centers inter-distances */ |
| 53 |
} VlIKMFilt ; |
| 54 |
|
| 55 |
/** @name Create and destroy |
| 56 |
** @{ */ |
| 57 |
VL_EXPORT VlIKMFilt *vl_ikm_new (int method) ; |
| 58 |
VL_EXPORT void vl_ikm_delete (VlIKMFilt *f) ; |
| 59 |
/** @} */ |
| 60 |
|
| 61 |
/** @name Process data |
| 62 |
** @{ */ |
| 63 |
VL_EXPORT void vl_ikm_init (VlIKMFilt *f, vl_ikmacc_t const *centers, vl_size M, vl_size K) ; |
| 64 |
VL_EXPORT void vl_ikm_init_rand (VlIKMFilt *f, vl_size M, vl_size K) ; |
| 65 |
VL_EXPORT void vl_ikm_init_rand_data (VlIKMFilt *f, vl_uint8 const *data, vl_size M, vl_size N, vl_size K) ; |
| 66 |
VL_EXPORT int vl_ikm_train (VlIKMFilt *f, vl_uint8 const *data, vl_size N) ; |
| 67 |
VL_EXPORT void vl_ikm_push (VlIKMFilt *f, vl_uint32 *asgn, vl_uint8 const *data, vl_size N) ; |
| 68 |
VL_EXPORT vl_uint vl_ikm_push_one (vl_ikmacc_t const *centers, vl_uint8 const *data, vl_size M, vl_size K) ; |
| 69 |
/** @} */ |
| 70 |
|
| 71 |
/** @name Retrieve data and parameters |
| 72 |
** @{ */ |
| 73 |
VL_EXPORT vl_size vl_ikm_get_ndims (VlIKMFilt const *f) ; |
| 74 |
VL_EXPORT vl_size vl_ikm_get_K (VlIKMFilt const *f) ; |
| 75 |
VL_EXPORT int vl_ikm_get_verbosity (VlIKMFilt const *f) ; |
| 76 |
VL_EXPORT vl_size vl_ikm_get_max_niters (VlIKMFilt const *f) ; |
| 77 |
VL_EXPORT vl_ikmacc_t const *vl_ikm_get_centers (VlIKMFilt const *f) ; |
| 78 |
/** @} */ |
| 79 |
|
| 80 |
/** @name Set parameters |
| 81 |
** @{ */ |
| 82 |
VL_EXPORT void vl_ikm_set_verbosity (VlIKMFilt *f, int verb) ; |
| 83 |
VL_EXPORT void vl_ikm_set_max_niters (VlIKMFilt *f, vl_size max_niters) ; |
| 84 |
/** @} */ |
| 85 |
|
| 86 |
/* VL_IKMEANS_H */ |
| 87 |
#endif |