bufferkdtree (C sources)
C source code for the Python bufferkdtree implementation
 All Classes Files Functions Variables Typedefs Macros
Functions
kdtree.c File Reference
#include "include/kdtree.h"
Include dependency graph for kdtree.c:

Functions

void kd_tree_init_tree_record (KD_TREE_RECORD *record, int kd_tree_depth, FLOAT_TYPE *Xtrain, int nXtrain, int dXtrain)
 
void kd_tree_free_tree_record (KD_TREE_RECORD *record)
 
void kd_tree_build_tree (KD_TREE_RECORD *kdtree_record, KD_TREE_PARAMETERS *params)
 
void kd_tree_build_recursive (KD_TREE_RECORD *kdtree_record, KD_TREE_PARAMETERS *params, int left, int right, int idx, int depth)
 
void kd_tree_query_tree_sequential (FLOAT_TYPE *test_pattern, FLOAT_TYPE *d_min, int *idx_min, int K, KD_TREE_RECORD *record)
 
void kd_tree_brute_force_leaf (void *XI, int dim, int fr_idx, int to_idx, FLOAT_TYPE *test_pattern, FLOAT_TYPE *d_min, int *idx_min, int K)
 
int kd_tree_find_best_split (int depth, int left, int right, KD_TREE_RECORD *kdtree_record, KD_TREE_PARAMETERS *params)
 
void kd_tree_generate_training_patterns_indices (KD_TREE_RECORD *kdtree_record)
 
int kd_tree_split_training_patterns_via_pivot (void *XI, int left, int right, int axis, int dim)
 
void kd_tree_insert (FLOAT_TYPE pattern_dist, int pattern_idx, FLOAT_TYPE *nearest_dist, int *nearest_idx, int K)
 

Function Documentation

void kd_tree_brute_force_leaf ( void *  XI,
int  dim,
int  fr_idx,
int  to_idx,
FLOAT_TYPE test_pattern,
FLOAT_TYPE d_min,
int *  idx_min,
int  K 
)

Brute-force nearest neigbhor search in a leaf of the tree (determined by fr_idx, to_idx, and XI).

Parameters
*XIPointer to array containing the patterns and the associated original training indices
dimDimensionality of the patterns
fr_idxThe from index in the array (left bound)
to_idxThe to index in the array (right bound)
*test_patternPointer to test pattern
*d_minPointer to array that shall contain the distances afterwards
*idx_minPointer to array that shall contain the indices afterwards
KNumber of nearest neighbors
void kd_tree_build_recursive ( KD_TREE_RECORD kdtree_record,
KD_TREE_PARAMETERS params,
int  left,
int  right,
int  idx,
int  depth 
)

Function to recursively build a kd tree

Parameters
*recordA kd tree record instance
*paramsAssociated kd tree parameters
leftleft bound for training patterns
rightright bound for training patterns
idxNode index
depthCurrent tree depth
void kd_tree_build_tree ( KD_TREE_RECORD kdtree_record,
KD_TREE_PARAMETERS params 
)

Builds the kd-tree (recursive construction)

Parameters
*recordA kd tree record instance
*paramsAssociated kd tree parameters
int kd_tree_find_best_split ( int  depth,
int  left,
int  right,
KD_TREE_RECORD kdtree_record,
KD_TREE_PARAMETERS params 
)

Finds the splitting axis.

Parameters
depthThe current tree depth
leftThe left bound
rightThe right bound
*kdtree_recordRecord storing the tree instances
*paramsStruct containing the parameters
void kd_tree_free_tree_record ( KD_TREE_RECORD record)

Frees space for the kd tree (e.g., nodes and leaves)

Parameters
*recordA kd tree record instance
void kd_tree_generate_training_patterns_indices ( KD_TREE_RECORD kdtree_record)

Parse patterns and store the original indices (this array of both the FLOAT_TYPEs and the indices) is sorted in-place during the construction of the kd-tree.

Parameters
*kdtree_recordRecord storing the tree instances
void kd_tree_init_tree_record ( KD_TREE_RECORD record,
int  kd_tree_depth,
FLOAT_TYPE Xtrain,
int  nXtrain,
int  dXtrain 
)

Initializes space for the kd tree (e.g., nodes and leaves)

Parameters
*recordThe kd tree struct instance
kd_tree_depthThe desired tree depth
*XtrainPointer to array containing the patterns (as FLOAT_TYPE)
nXtrainNumber of patterns
nXtrainDimensionality of each pattern
void kd_tree_insert ( FLOAT_TYPE  pattern_dist,
int  pattern_idx,
FLOAT_TYPE nearest_dist,
int *  nearest_idx,
int  K 
)

Inserts the value pattern_dist with index pattern_idx in the list nearest_dist of FLOAT_TYPEs and the list nearest_idx of indices. Both lists contain at most K elements.

Parameters
pattern_distDistance to the (current) pattern
pattern_idxThe index of the (current) pattern
*nearest_distThe array of floats to be updated
*nearest_idxThe array of indices to be updated
KThe number of nearest neighbors
void kd_tree_query_tree_sequential ( FLOAT_TYPE test_pattern,
FLOAT_TYPE d_min,
int *  idx_min,
int  K,
KD_TREE_RECORD record 
)

Queries the kd-tree to obtain the nearest neigbhors, sequential version.

Parameters
*test_patternThe test pattern for which the nearest neighbors shall be computed
*d_minFloat array that shall contain the distances
*idx_minInteger array to store the nearest neighbor indices
KNumber of nearest neigbhors that shall be found
*recordA kd tree record instance
int kd_tree_split_training_patterns_via_pivot ( void *  XI,
int  left,
int  right,
int  axis,
int  dim 
)

Sorts the training patterns in range left to right (inclusive) with respect to "axis".

Parameters
*XIPointer to array containing the patterns and the associated original training indices
leftLeft bound
rightRight bound
axisThe current axis
dimThe dimensionality of the patterns