| 1 |
/** @file aib.h |
| 2 |
** @brief AIB (@ref aib) |
| 3 |
** @author Brian Fulkerson |
| 4 |
** @author Andrea Vedaldi |
| 5 |
**/ |
| 6 |
|
| 7 |
/* |
| 8 |
Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. |
| 9 |
All rights reserved. |
| 10 |
|
| 11 |
This file is part of the VLFeat library and is made available under |
| 12 |
the terms of the BSD license (see the COPYING file). |
| 13 |
*/ |
| 14 |
|
| 15 |
#ifndef VL_AIB_H |
| 16 |
#define VL_AIB_H |
| 17 |
|
| 18 |
#include "generic.h" |
| 19 |
#include "mathop.h" |
| 20 |
|
| 21 |
/** ------------------------------------------------------------------ |
| 22 |
** @internal |
| 23 |
** @brief AIB algorithm data |
| 24 |
** |
| 25 |
** The implementation is quite straightforward, but the way feature |
| 26 |
** values are handled in order to support efficient joins, |
| 27 |
** deletions and re-arrangement needs to be explained. This is |
| 28 |
** achieved by adding a layer of indirection: |
| 29 |
** - Call each feature value (either original or obtained by a join |
| 30 |
** operation) a <em>node</em>. Nodes are identified by numbers. |
| 31 |
** - Call each element of the various arrays (such as VlAIB::Px) |
| 32 |
** an <em>entry</em>. |
| 33 |
** - Entries are dynamically associated to nodes as specified by |
| 34 |
** VlAIB::nodes. For example, @c Px[i] refers to the node @c |
| 35 |
** nodes[i]. |
| 36 |
**/ |
| 37 |
|
| 38 |
typedef struct _VlAIB |
| 39 |
{ |
| 40 |
vl_uint *nodes ; /**< Entires to nodes */ |
| 41 |
vl_uint nentries ; /**< Total number of entries (= # active nodes) */ |
| 42 |
double *beta ; /**< Minimum distance to an entry */ |
| 43 |
vl_uint *bidx ; /**< Closest entry */ |
| 44 |
|
| 45 |
|
| 46 |
vl_uint *which ; /**< List of entries to update */ |
| 47 |
vl_uint nwhich ; /**< Number of entries to update */ |
| 48 |
|
| 49 |
double *Pcx; /**< Joint probability table */ |
| 50 |
double *Px; /**< Marginal. */ |
| 51 |
double *Pc; /**< Marginal. */ |
| 52 |
vl_uint nvalues; /**< Number of feature values */ |
| 53 |
vl_uint nlabels; /**< Number of labels */ |
| 54 |
|
| 55 |
vl_uint *parents; /**< Array of parents */ |
| 56 |
double *costs; /**< Cost of each merge */ |
| 57 |
|
| 58 |
vl_uint verbosity ; /** Verbosity level */ |
| 59 |
} VlAIB; |
| 60 |
|
| 61 |
/** @name Create and destroy |
| 62 |
** @{ |
| 63 |
**/ |
| 64 |
VL_EXPORT |
| 65 |
VlAIB * vl_aib_new(double * Pcx, vl_uint nvalues, vl_uint nlabels); |
| 66 |
|
| 67 |
VL_EXPORT |
| 68 |
void vl_aib_delete (VlAIB * aib); |
| 69 |
/** @} */ |
| 70 |
|
| 71 |
/** @name Process data |
| 72 |
** @{ |
| 73 |
**/ |
| 74 |
VL_EXPORT |
| 75 |
void vl_aib_process(VlAIB * aib); |
| 76 |
/** @} */ |
| 77 |
|
| 78 |
/** @name Retrieve results |
| 79 |
** @{ |
| 80 |
**/ |
| 81 |
VL_INLINE vl_uint * vl_aib_get_parents(VlAIB const * aib); |
| 82 |
VL_INLINE double * vl_aib_get_costs(VlAIB const * aib); |
| 83 |
/** @} */ |
| 84 |
|
| 85 |
|
| 86 |
/* ------------------------------------------------------------------- |
| 87 |
* Inline functions implementation |
| 88 |
* ---------------------------------------------------------------- */ |
| 89 |
|
| 90 |
/** ------------------------------------------------------------------ |
| 91 |
** @brief Get resulting list of parents |
| 92 |
** @param aib AIB filter. |
| 93 |
** @return An array of parents |
| 94 |
**/ |
| 95 |
VL_INLINE |
| 96 |
vl_uint * vl_aib_get_parents(VlAIB const * aib) |
| 97 |
{ |
| 98 |
return aib->parents; |
| 99 |
} |
| 100 |
|
| 101 |
/** ------------------------------------------------------------------ |
| 102 |
** @brief Get a list of merge costs |
| 103 |
** @param aib AIB filter. |
| 104 |
** @return An array of costs |
| 105 |
**/ |
| 106 |
VL_INLINE |
| 107 |
double * vl_aib_get_costs(VlAIB const * aib) |
| 108 |
{ |
| 109 |
return aib->costs; |
| 110 |
} |
| 111 |
|
| 112 |
/* ----------------------------------------------------------------- */ |
| 113 |
/** @brief Set the verbosity |
| 114 |
** @param self AIB object. |
| 115 |
** @param verbosity a non-negative integer. |
| 116 |
**/ |
| 117 |
VL_INLINE void |
| 118 |
vl_aib_set_verbosity (VlAIB * self, int verbosity) |
| 119 |
{ |
| 120 |
self->verbosity = verbosity ; |
| 121 |
} |
| 122 |
|
| 123 |
/** @brief Get the verbosity |
| 124 |
** @param self AIB object. |
| 125 |
** @return the verbosity level. |
| 126 |
**/ |
| 127 |
VL_INLINE int |
| 128 |
vl_aib_get_verbosity (VlAIB const * self) |
| 129 |
{ |
| 130 |
return self->verbosity ; |
| 131 |
} |
| 132 |
|
| 133 |
/* VL_AIB_H */ |
| 134 |
#endif |