From ada1f1db81d89663a2d01123ed37ed1723a79823 Mon Sep 17 00:00:00 2001 From: lambday Date: Tue, 5 Jul 2016 16:15:26 +0100 Subject: [PATCH] cleaned up and optimized multi-kernel permutation test --- .../mmd/MultiKernelPermutationTest.cpp | 98 +++++++------------ 1 file changed, 38 insertions(+), 60 deletions(-) diff --git a/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTest.cpp b/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTest.cpp index eda936618aa..b16d13acf2c 100644 --- a/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTest.cpp +++ b/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTest.cpp @@ -28,29 +28,13 @@ * either expressed or implied, of the Shogun Development Team. */ -#include #include -#include -#include -#include +#include #include -#include -#include #include #include -#include #include -// TODO remove -#include -#include - -using Eigen::MatrixXd; -using Eigen::Map; -using std::cout; -using std::endl; -// TODO remove - using namespace shogun; using namespace internal; using namespace mmd; @@ -150,59 +134,53 @@ SGVector MultiKernelPermutationTest::operator()(const KernelManager& kerne inverted_permuted_inds[n][permuted_inds[i]]=i; } - SGVector statistic(kernel_mgr.num_kernels()); - std::vector stat_terms(kernel_mgr.num_kernels()); - for (auto col=0; col null_samples(num_null_samples); + SGVector result(kernel_mgr.num_kernels()); + + const index_t size=n_x+n_y; + SGVector km(size*(size+1)/2); +#pragma omp parallel { - for (auto row=col; rowkernel(row, col); - add_term(stat_terms[k], kernel_value, row, col); + for (auto col=row; colkernel(row, col); + add_term(stat_terms, km[index], row, col); + } } - } - } - for (size_t k=0; k null_samples(kernel_mgr.num_kernels(), num_null_samples); - Map null_samples_map(null_samples.data(), null_samples.num_rows, null_samples.num_cols); -#pragma omp parallel for - for (auto n=0; n terms(kernel_mgr.num_kernels()); - for (auto col=0; colkernel(row, col); - add_term(terms[k], kernel_value, row_inds_inv, col_inds_inv); + for (auto col=row; col result(kernel_mgr.num_kernels()); - MatrixXd transposed_null_samples=null_samples_map.transpose(); - for (size_t k=0; k null_samples_k(transposed_null_samples.col(k).data(), num_null_samples, false); - std::sort(null_samples_k.data(), null_samples_k.data()+null_samples_k.size()); - SG_SDEBUG("statistic=%f\n", statistic[k]); - float64_t idx=null_samples_k.find_position_to_insert(statistic[k]); - SG_SDEBUG("index=%f\n", idx); - auto p_value=1.0-idx/num_null_samples; - bool rejected=p_value