From 4de9e7109a70dcf95e69fa0446bd59af4ef93df4 Mon Sep 17 00:00:00 2001 From: Dongryeol Lee Date: Mon, 18 Feb 2008 19:05:46 +0000 Subject: [PATCH] Some performance tuning --- fastlib2/contrib/dongryel/regression/dense_lpr.h | 13 +++++++++++++ .../contrib/dongryel/regression/dense_lpr_impl.h | 9 ++++++++- .../contrib/dongryel/regression/dense_lpr_main.cc | 4 ++++ .../dongryel/regression/relative_prune_lpr.h | 4 ++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/fastlib2/contrib/dongryel/regression/dense_lpr.h b/fastlib2/contrib/dongryel/regression/dense_lpr.h index 4435804302..0904ed5c19 100644 --- a/fastlib2/contrib/dongryel/regression/dense_lpr.h +++ b/fastlib2/contrib/dongryel/regression/dense_lpr.h @@ -429,6 +429,12 @@ class DenseLpr { ////////// Private Member Variables ////////// + /** @brief The number of finite difference prunes. */ + int num_finite_difference_prunes_; + + /** @brief The number of far-field prunes. */ + int num_far_field_prunes_; + /** @brief The local polynomial order. */ int lpr_order_; @@ -757,11 +763,18 @@ class DenseLpr { Vector *query_magnitude_weight_diagrams, Vector *query_influence_values) { + // Clear prune statistics. + num_finite_difference_prunes_ = num_far_field_prunes_ = 0; + // This is the basic N-body based computation. BasicCompute_(queries, query_regression_estimates, query_confidence_bands, query_magnitude_weight_diagrams, query_influence_values); + printf("Number of finite difference prunes: %d\n", + num_finite_difference_prunes_); + printf("Number of far-field prunes: %d\n", num_far_field_prunes_); + // If the reference dataset is being used for training, then // compute variance and degrees of freedom. if(query_influence_values != NULL) { diff --git a/fastlib2/contrib/dongryel/regression/dense_lpr_impl.h b/fastlib2/contrib/dongryel/regression/dense_lpr_impl.h index 8ff1c85a9d..496b7f17e8 100644 --- a/fastlib2/contrib/dongryel/regression/dense_lpr_impl.h +++ b/fastlib2/contrib/dongryel/regression/dense_lpr_impl.h @@ -473,6 +473,9 @@ void DenseLpr::DualtreeLprCanonical_ &(qnode->stat().postponed_weight_diagram_numerator_e_)); qnode->stat().postponed_weight_diagram_numerator_used_error_ += delta_weight_diagram_numerator_used_error; + + // Keep track of the number of finite difference prunes. + num_finite_difference_prunes_++; return; } @@ -480,7 +483,8 @@ void DenseLpr::DualtreeLprCanonical_ // moments if the maximum distance between the two nodes is within // the bandwidth! This if-statement does not apply to the Gaussian // kernel, so I need to fix in the future! - if(kernel_aux_.kernel_.bandwidth_sq() >= dsqd_range.hi) { + if(kernel_aux_.kernel_.bandwidth_sq() >= dsqd_range.hi && + rnode->count() > 32) { for(index_t q = qnode->begin(); q < qnode->end(); q++) { for(index_t j = 0; j < row_length_; j++) { @@ -512,6 +516,9 @@ void DenseLpr::DualtreeLprCanonical_ la::AddTo(weight_diagram_numerator_dl, &(qnode->stat().postponed_weight_diagram_numerator_l_)); + + // Keep track of the far-field prunes. + num_far_field_prunes_++; return; } diff --git a/fastlib2/contrib/dongryel/regression/dense_lpr_main.cc b/fastlib2/contrib/dongryel/regression/dense_lpr_main.cc index c80098c949..e684764ca3 100644 --- a/fastlib2/contrib/dongryel/regression/dense_lpr_main.cc +++ b/fastlib2/contrib/dongryel/regression/dense_lpr_main.cc @@ -55,18 +55,22 @@ int main(int argc, char *argv[]) { DatasetScaler::ScaleDataByMinMax(queries, references, false); // Do fast algorithm. + printf("Running the fast algorithm...\n"); Vector fast_lpr_results; DenseLpr fast_lpr; fast_lpr.Init(references, reference_targets, local_linear_module); fast_lpr.PrintDebug(); fast_lpr.get_regression_estimates(&fast_lpr_results); + printf("Finished running the fast algorithm...\n"); // Do naive algorithm. + printf("Running the naive algorithm...\n"); Vector naive_lpr_results; NaiveLpr naive_lpr; naive_lpr.Init(references, reference_targets, local_linear_module); naive_lpr.PrintDebug(); naive_lpr.get_regression_estimates(&naive_lpr_results); + printf("Finished running the naive algorithm...\n"); printf("Maximum relative difference: %g\n", MatrixUtil::MaxRelativeDifference(naive_lpr_results, diff --git a/fastlib2/contrib/dongryel/regression/relative_prune_lpr.h b/fastlib2/contrib/dongryel/regression/relative_prune_lpr.h index 2ef2d61f5a..1e65efb348 100644 --- a/fastlib2/contrib/dongryel/regression/relative_prune_lpr.h +++ b/fastlib2/contrib/dongryel/regression/relative_prune_lpr.h @@ -122,12 +122,12 @@ class RelativePruneLpr { denominator_used_error = kernel_error * (rnode->stat().sum_data_outer_products_error_norm_); denominator_n_pruned = rnode->stat().sum_data_outer_products_alloc_norm_; - + // The total norm error for each query point for approximating // the B^T W(q)^2 B matrix. weight_diagram_numerator_used_error = squared_kernel_error * (rnode->stat().sum_data_outer_products_error_norm_); - + // Check pruning condition. return (numerator_used_error <= numerator_allowed_err && denominator_used_error <= denominator_allowed_err &&