From cb523e355223c9990f5e079de2a4e88b196ee39d Mon Sep 17 00:00:00 2001 From: Heiko Strathmann Date: Wed, 27 Mar 2013 18:05:55 +0000 Subject: [PATCH] added all three methods for null approximation to precomputed kernel test --- .../statistics/QuadraticTimeMMD_unittest.cc | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/tests/unit/statistics/QuadraticTimeMMD_unittest.cc b/tests/unit/statistics/QuadraticTimeMMD_unittest.cc index 5a1c97061db..04a29f665a0 100644 --- a/tests/unit/statistics/QuadraticTimeMMD_unittest.cc +++ b/tests/unit/statistics/QuadraticTimeMMD_unittest.cc @@ -223,16 +223,21 @@ TEST(QuadraticTimeMMD,custom_kernel_vs_normal_kernel) float64_t alpha=0.05; mmd->set_null_approximation_method(BOOTSTRAP); + mmd->set_statistic_type(BIASED); mmd->set_bootstrap_iterations(3); + mmd->set_num_eigenvalues_spectrum(3); + mmd->set_num_samples_sepctrum(250); /* compute tpye I and II error using normal and precomputed kernel */ index_t num_trials=3; - SGVector type_I_errors(num_trials); - SGVector type_II_errors(num_trials); SGVector type_I_mmds(num_trials); - SGVector type_I_threshs(num_trials); + SGVector type_I_threshs_boot(num_trials); + SGVector type_I_threshs_spectrum(num_trials); + SGVector type_I_threshs_gamma(num_trials); SGVector type_II_mmds(num_trials); - SGVector type_II_threshs(num_trials); + SGVector type_II_threshs_boot(num_trials); + SGVector type_II_threshs_spectrum(num_trials); + SGVector type_II_threshs_gamma(num_trials); SGVector inds(2*m); inds.range_fill(); @@ -246,31 +251,40 @@ TEST(QuadraticTimeMMD,custom_kernel_vs_normal_kernel) inds.permute(); p_and_q->add_subset(inds); type_I_mmds[i]=mmd->compute_statistic(); - type_I_threshs[i]=mmd->compute_threshold(alpha); - type_I_errors[i]=type_I_mmds[i]set_null_approximation_method(BOOTSTRAP); + type_I_threshs_boot[i]=mmd->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_SPECTRUM); + type_I_threshs_spectrum[i]=mmd->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_GAMMA); + type_I_threshs_gamma[i]=mmd->compute_threshold(alpha); p_and_q->remove_subset(); type_II_mmds[i]=mmd->compute_statistic(); - type_II_threshs[i]=mmd->compute_threshold(alpha); - type_II_errors[i]=type_II_mmds[i]set_null_approximation_method(BOOTSTRAP); + type_II_threshs_boot[i]=mmd->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_SPECTRUM); + type_II_threshs_spectrum[i]=mmd->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_GAMMA); + type_II_threshs_gamma[i]=mmd->compute_threshold(alpha); + } SG_UNREF(p_and_q); //SG_SPRINT("normal kernel\n"); - //type_I_errors.display_vector("type_I_errors"); - //type_II_errors.display_vector("type_II_errors"); //type_I_mmds.display_vector("type_I_mmds"); - //type_I_threshs.display_vector("type_I_threshs"); + //type_I_threshs_boot.display_vector("type_I_threshs_boot"); //type_II_mmds.display_vector("type_II_mmds"); - //type_II_threshs.display_vector("type_II_threshs"); + //type_II_threshs_boot.display_vector("type_II_threshs_boot"); /* same thing with precomputed kernel */ - SGVector type_I_errors_pre(num_trials); - SGVector type_II_errors_pre(num_trials); SGVector type_I_mmds_pre(num_trials); - SGVector type_I_threshs_pre(num_trials); + SGVector type_I_threshs_boot_pre(num_trials); + SGVector type_I_threshs_spectrum_pre(num_trials); + SGVector type_I_threshs_gamma_pre(num_trials); SGVector type_II_mmds_pre(num_trials); - SGVector type_II_threshs_pre(num_trials); + SGVector type_II_threshs_boot_pre(num_trials); + SGVector type_II_threshs_spectrum_pre(num_trials); + SGVector type_II_threshs_gamma_pre(num_trials); kernel->init(p_and_q, p_and_q); CCustomKernel* precomputed=new CCustomKernel(kernel); CQuadraticTimeMMD* mmd2=new CQuadraticTimeMMD(precomputed, m); @@ -285,32 +299,41 @@ TEST(QuadraticTimeMMD,custom_kernel_vs_normal_kernel) precomputed->add_row_subset(inds); precomputed->add_col_subset(inds); type_I_mmds_pre[i]=mmd2->compute_statistic(); - type_I_threshs_pre[i]=mmd2->compute_threshold(alpha); - type_I_errors_pre[i]=type_I_mmds_pre[i]set_null_approximation_method(BOOTSTRAP); + type_I_threshs_boot_pre[i]=mmd2->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_SPECTRUM); + type_I_threshs_spectrum_pre[i]=mmd2->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_GAMMA); + type_I_threshs_gamma_pre[i]=mmd2->compute_threshold(alpha); precomputed->remove_row_subset(); precomputed->remove_col_subset(); type_II_mmds_pre[i]=mmd2->compute_statistic(); - type_II_threshs_pre[i]=mmd2->compute_threshold(alpha); - type_II_errors_pre[i]=type_II_mmds_pre[i]set_null_approximation_method(BOOTSTRAP); + type_II_threshs_boot_pre[i]=mmd2->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_SPECTRUM); + type_II_threshs_spectrum_pre[i]=mmd2->compute_threshold(alpha); + mmd->set_null_approximation_method(MMD2_GAMMA); + type_II_threshs_gamma_pre[i]=mmd2->compute_threshold(alpha); + } //SG_SPRINT("precomputed kernel\n"); - //type_I_errors_pre.display_vector("type_I_errors"); - //type_II_errors_pre.display_vector("type_II_errors"); //type_I_mmds_pre.display_vector("type_I_mmds"); - //type_I_threshs_pre.display_vector("type_I_threshs"); + //type_I_threshs_boot_pre.display_vector("type_I_threshs_boot"); //type_II_mmds_pre.display_vector("type_II_mmds"); - //type_II_threshs_pre.display_vector("type_II_threshs"); + //type_II_threshs_boot_pre.display_vector("type_II_threshs_boot"); for (index_t i=0; i