From 5d9ddcbd7ab291a4e2ac0c9ce09499e6ea9633cb Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Wed, 3 Nov 2010 20:37:51 +0000 Subject: [PATCH] Monochromatic trick added for three-body. --- .../core/gnp/tripletree_dfs_dev.h | 31 ++++++++++++++++--- .../thesis_research/core/table/table.h | 11 +++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/gnp/tripletree_dfs_dev.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/gnp/tripletree_dfs_dev.h index b6249596f3..55e0d5bc16 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/gnp/tripletree_dfs_dev.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/gnp/tripletree_dfs_dev.h @@ -62,6 +62,19 @@ void core::gnp::TripletreeDfs::Compute( core::gnp::TripleRangeDistanceSq triple_range_distance_sq; triple_range_distance_sq.Init(metric, *table_, root_nodes); + // Monochromatic computation. + std::vector< typename TableType::TreeType *> leaf_nodes; + table_->get_leaf_nodes(table_->get_tree(), &leaf_nodes); + for(unsigned int i = 0; i < leaf_nodes.size(); i++) { + std::vector< TreeType *> leaf_node_tuples(3, leaf_nodes[i]); + core::gnp::TripleRangeDistanceSq range_sq_in; + range_sq_in.Init(metric, *table_, leaf_node_tuples); + TripletreeBase_( + metric, range_sq_in, query_results); + } + PostProcess_(metric, table_->get_tree(), query_results, false); + + PreProcess_(table_->get_tree()); std::vector top_failure_probabilities( 3, 1.0 - problem_->global().probability()); @@ -167,8 +180,6 @@ void core::gnp::TripletreeDfs::TripletreeBase_( distance_sq_set.ReplaceOnePoint( metric, third_point, third_point_index, 2); - - // Add the contribution due to the triple that has been chosen // to each of the query point. problem_->global().ApplyContribution( @@ -314,9 +325,11 @@ void core::gnp::TripletreeDfs::ProbabilisticSummarize_( const typename ProblemType::DeltaType &delta, typename ProblemType::ResultType *query_results) { + // Apply the deterministic prunes. Summarize_( range_in, probabilistic_node_start_index, delta, query_results); + // Apply the probabilistic prunes. query_results->ApplyProbabilisticDelta( global, range_in, failure_probabilities, probabilistic_node_start_index, delta); @@ -333,7 +346,8 @@ void core::gnp::TripletreeDfs::ProbabilisticSummarize_( template bool core::gnp::TripletreeDfs::CanSummarize_( - const core::gnp::TripleRangeDistanceSq &triple_range_distance_sq_in, + const core::gnp::TripleRangeDistanceSq + &triple_range_distance_sq_in, const typename ProblemType::DeltaType &delta, typename ProblemType::ResultType *query_results, int *failure_index) { @@ -438,8 +452,15 @@ void core::gnp::TripletreeDfs::RecursionHelper_( bool exact_computation = true; if(all_leaves) { - // Call the base case when all three nodes are leaves. - TripletreeBase_(metric, triple_range_distance_sq, query_results); + if(!( + triple_range_distance_sq.node(0) == + triple_range_distance_sq.node(1) && + triple_range_distance_sq.node(1) == + triple_range_distance_sq.node(2))) { + + // Call the base case when all three nodes are leaves. + TripletreeBase_(metric, triple_range_distance_sq, query_results); + } } else { diff --git a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h index f39cb6bff8..b6f033c061 100644 --- a/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h +++ b/fastlib/trunk/contrib/dongryel/thesis_research/core/table/table.h @@ -198,6 +198,17 @@ class Table: public boost::noncopyable { return tree_; } + void get_leaf_nodes( + TreeType *node, std::vector< TreeType *> *leaf_nodes) { + if(node->is_leaf()) { + leaf_nodes->push_back(node); + } + else { + get_leaf_nodes(node->left(), leaf_nodes); + get_leaf_nodes(node->right(), leaf_nodes); + } + } + int n_attributes() const { return data_.n_rows(); }