1
/* ====================================================================
2
* Copyright (c) 2005 Carnegie Mellon University. All rights
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in
14
* the documentation and/or other materials provided with the
17
* This work was supported in part by funding from the Defense Advanced
18
* Research Projects Agency and the National Science Foundation of the
19
* United States of America, and the CMU Sphinx Speech Consortium.
21
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
22
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
25
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
* ====================================================================
36
/*********************************************************************
40
* Description: kd-tree implementation for mixture Gaussians
42
* Author: David Huggins-Daines <dhuggins@cs.cmu.edu>
44
*********************************************************************/
56
#include "sphinxbase/prim_type.h"
57
#include "s3/gauden.h"
58
#include "s3/vector.h"
60
typedef struct kd_tree_node_s kd_tree_node_t;
61
struct kd_tree_node_s {
62
const vector_t *means, *variances; /* Codebook of Gaussians, shared by all nodes */
63
float32 **boxes; /* Gaussian boxes for codebook, shared by all nodes */
64
float32 threshold; /* Threshold for Gaussian boxes */
65
uint32 n_level; /* Number of levels (0 for non-root) */
66
uint32 n_density, n_comp; /* Number of densities, number of components. */
67
uint8 *bbi; /* BBI vector of intersecting Gaussians */
68
vector_t lower, upper; /* Lower and upper coordinates of projection */
69
uint32 split_comp; /* Dimension in which split is done */
70
float32 split_plane; /* Hyperplane splitting this node */
71
kd_tree_node_t *left, *right; /* Child nodes */
74
kd_tree_node_t *build_kd_tree(const vector_t *means, const vector_t *variances,
75
uint32 n_density, uint32 n_comp,
76
float32 threshold, int32 n_levels,
78
void free_kd_tree(kd_tree_node_t *tree);
80
int32 write_kd_trees(const char *outfile, kd_tree_node_t **trees, uint32 n_trees);
81
int32 read_kd_trees(const char *infile, kd_tree_node_t ***out_trees, uint32 *out_n_trees);
86
#endif /* __KDTREE_H__ */