Definition at line 1032 of file cluster-utils.cc.
◆ TreeClusterer()
◆ ~TreeClusterer()
Definition at line 1057 of file cluster-utils.cc.
References kaldi::DeletePointers().
1058 for (
int32 leaf = 0; leaf < static_cast<int32>(
leaf_nodes_.size());leaf++) {
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
std::vector< Node * > leaf_nodes_
std::vector< Node * > nonleaf_nodes_
◆ Cluster()
Definition at line 1042 of file cluster-utils.cc.
References BottomUpClusterer::ans_, and BottomUpClusterer::queue_.
Referenced by kaldi::TreeCluster().
1047 std::pair<BaseFloat, Node*> pr =
queue_.top();
1052 CreateOutput(clusters_out, assignments_out, clust_assignments_out,
void CreateOutput(std::vector< Clusterable *> *clusters_out, std::vector< int32 > *assignments_out, std::vector< int32 > *clust_assignments_out, int32 *num_leaves_out)
std::priority_queue< std::pair< BaseFloat, Node * > > queue_
std::vector< Node * > leaf_nodes_
◆ CreateAssignmentsOutput()
void CreateAssignmentsOutput |
( |
std::vector< int32 > * |
assignments_out | ) |
|
|
inlineprivate |
Definition at line 1106 of file cluster-utils.cc.
References rnnlm::i, KALDI_ASSERT, and BottomUpClusterer::points_.
1107 assignments_out->clear();
1109 for (
int32 leaf = 0; leaf < static_cast<int32>(
leaf_nodes_.size()); leaf++) {
1110 std::vector<int32> &indices =
leaf_nodes_[leaf]->leaf.point_indices;
1111 for (
int32 i = 0; i < static_cast<int32>(indices.size());
i++) {
1114 (*assignments_out)[indices[
i]] = leaf;
1117 #ifdef KALDI_PARANOID 1118 for (
size_t i = 0;i<assignments_out->size();i++)
KALDI_ASSERT((*assignments_out)[
i] != (
int32)(-1));
const std::vector< Clusterable * > & points_
std::vector< Node * > leaf_nodes_
#define KALDI_ASSERT(cond)
◆ CreateClustAssignmentsOutput()
void CreateClustAssignmentsOutput |
( |
std::vector< int32 > * |
clust_assignments_out | ) |
|
|
inlineprivate |
Definition at line 1121 of file cluster-utils.cc.
References KALDI_ASSERT.
1123 for (
int32 leaf = 0; leaf < static_cast<int32>(
leaf_nodes_.size()); leaf++) {
1132 (*clust_assignments_out)[leaf] = parent_index;
1137 if (
nonleaf_nodes_[nonleaf]->parent == NULL) parent_index = index;
1142 (*clust_assignments_out)[index] = parent_index;
int32 NonleafOutputIndex(int32 index)
std::vector< Node * > leaf_nodes_
#define KALDI_ASSERT(cond)
std::vector< Node * > nonleaf_nodes_
◆ CreateClustersOutput()
void CreateClustersOutput |
( |
std::vector< Clusterable *> * |
clusters_out | ) |
|
|
inlineprivate |
Definition at line 1145 of file cluster-utils.cc.
1147 for (
int32 leaf = 0; leaf < static_cast<int32>(
leaf_nodes_.size()); leaf++) {
1148 (*clusters_out)[leaf] =
leaf_nodes_[leaf]->node_total;
int32 NonleafOutputIndex(int32 index)
std::vector< Node * > leaf_nodes_
std::vector< Node * > nonleaf_nodes_
◆ CreateOutput()
void CreateOutput |
( |
std::vector< Clusterable *> * |
clusters_out, |
|
|
std::vector< int32 > * |
assignments_out, |
|
|
std::vector< int32 > * |
clust_assignments_out, |
|
|
int32 * |
num_leaves_out |
|
) |
| |
|
inlineprivate |
Definition at line 1088 of file cluster-utils.cc.
1092 if (num_leaves_out) *num_leaves_out =
leaf_nodes_.size();
1093 if (assignments_out)
1095 if (clust_assignments_out)
void CreateAssignmentsOutput(std::vector< int32 > *assignments_out)
std::vector< Node * > leaf_nodes_
void CreateClustAssignmentsOutput(std::vector< int32 > *clust_assignments_out)
void CreateClustersOutput(std::vector< Clusterable *> *clusters_out)
◆ DoSplit()
void DoSplit |
( |
Node * |
node | ) |
|
|
inlineprivate |
Definition at line 1157 of file cluster-utils.cc.
References TreeClusterer::Node::assignments, TreeClusterer::Node::best_split, TreeClusterer::Node::children, TreeClusterer::Node::clusters, rnnlm::i, TreeClusterer::Node::index, TreeClusterer::Node::is_leaf, KALDI_ASSERT, TreeClusterer::Node::leaf, TreeClusterer::Node::node_total, TreeClusterer::Node::parent, TreeClusterer::Node::point_indices, and TreeClusterer::Node::points.
1162 Node *child =
new Node;
1163 node->children[
i] = child;
1164 child->is_leaf =
true;
1165 child->parent = node;
1166 child->node_total = node->leaf.clusters[
i];
1168 child->index = node->index;
1176 KALDI_ASSERT(node->leaf.assignments.size() == node->leaf.points.size());
1177 KALDI_ASSERT(node->leaf.point_indices.size() == node->leaf.points.size());
1178 for (
int32 i = 0; i < static_cast<int32>(node->leaf.points.size());
i++) {
1179 int32 child_index = node->leaf.assignments[
i];
1181 node->children[child_index]->leaf.points.push_back(node->leaf.points[
i]);
1182 node->children[child_index]->leaf.point_indices.push_back(node->leaf.point_indices[
i]);
1184 node->leaf.points.clear();
1185 node->leaf.point_indices.clear();
1186 node->leaf.clusters.clear();
1187 node->leaf.assignments.clear();
1188 node->is_leaf =
false;
std::vector< Node * > leaf_nodes_
#define KALDI_ASSERT(cond)
void FindBestSplit(Node *node)
std::vector< Node * > nonleaf_nodes_
◆ FindBestSplit()
void FindBestSplit |
( |
Node * |
node | ) |
|
|
inlineprivate |
Definition at line 1194 of file cluster-utils.cc.
References TreeClusterer::Node::assignments, TreeClusterer::Node::best_split, kaldi::ClusterKMeans(), TreeClusterer::Node::clusters, TreeClusterer::Node::is_leaf, KALDI_ASSERT, KALDI_WARN, TreeClusterer::Node::leaf, TreeClusterer::Node::points, and BottomUpClusterer::queue_.
1197 if (node->leaf.points.size() == 0) {
1198 KALDI_WARN <<
"Warning: tree clustering: leaf with no data";
1199 node->leaf.best_split = 0;
return;
1201 if (node->leaf.points.size()<=1) { node->leaf.best_split = 0;
return; }
1206 &node->leaf.clusters,
1207 &node->leaf.assignments,
1209 node->leaf.best_split = impr;
1211 queue_.push(std::make_pair(impr, node));
std::priority_queue< std::pair< BaseFloat, Node * > > queue_
BaseFloat ClusterKMeans(const std::vector< Clusterable *> &points, int32 num_clust, std::vector< Clusterable *> *clusters_out, std::vector< int32 > *assignments_out, ClusterKMeansOptions cfg)
ClusterKMeans is a K-means-like clustering algorithm.
#define KALDI_ASSERT(cond)
ClusterKMeansOptions kmeans_cfg
◆ Init()
◆ NonleafOutputIndex()
Definition at line 1103 of file cluster-utils.cc.
std::vector< Node * > leaf_nodes_
std::vector< Node * > nonleaf_nodes_
◆ ans_
◆ cfg_
◆ leaf_nodes_
std::vector<Node*> leaf_nodes_ |
|
private |
◆ max_clust_
◆ nonleaf_nodes_
std::vector<Node*> nonleaf_nodes_ |
|
private |
◆ points_
◆ queue_
The documentation for this class was generated from the following file: