Skip to content

Commit

Permalink
added all three methods for null approximation to precomputed kernel …
Browse files Browse the repository at this point in the history
…test
  • Loading branch information
karlnapf committed Mar 27, 2013
1 parent 978b5b2 commit cb523e3
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions tests/unit/statistics/QuadraticTimeMMD_unittest.cc
Expand Up @@ -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<float64_t> type_I_errors(num_trials);
SGVector<float64_t> type_II_errors(num_trials);
SGVector<float64_t> type_I_mmds(num_trials);
SGVector<float64_t> type_I_threshs(num_trials);
SGVector<float64_t> type_I_threshs_boot(num_trials);
SGVector<float64_t> type_I_threshs_spectrum(num_trials);
SGVector<float64_t> type_I_threshs_gamma(num_trials);
SGVector<float64_t> type_II_mmds(num_trials);
SGVector<float64_t> type_II_threshs(num_trials);
SGVector<float64_t> type_II_threshs_boot(num_trials);
SGVector<float64_t> type_II_threshs_spectrum(num_trials);
SGVector<float64_t> type_II_threshs_gamma(num_trials);

SGVector<index_t> inds(2*m);
inds.range_fill();
Expand All @@ -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]<type_I_threshs[i];
mmd->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]<type_II_threshs[i];
mmd->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<float64_t> type_I_errors_pre(num_trials);
SGVector<float64_t> type_II_errors_pre(num_trials);
SGVector<float64_t> type_I_mmds_pre(num_trials);
SGVector<float64_t> type_I_threshs_pre(num_trials);
SGVector<float64_t> type_I_threshs_boot_pre(num_trials);
SGVector<float64_t> type_I_threshs_spectrum_pre(num_trials);
SGVector<float64_t> type_I_threshs_gamma_pre(num_trials);
SGVector<float64_t> type_II_mmds_pre(num_trials);
SGVector<float64_t> type_II_threshs_pre(num_trials);
SGVector<float64_t> type_II_threshs_boot_pre(num_trials);
SGVector<float64_t> type_II_threshs_spectrum_pre(num_trials);
SGVector<float64_t> 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);
Expand All @@ -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]<type_I_threshs_pre[i];
mmd->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]<type_II_threshs_pre[i];
mmd->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<num_trials; ++i)
{
EXPECT_LE(CMath::abs(type_I_errors[i]-type_I_errors_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_II_errors_pre[i]-type_II_errors_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_I_mmds_pre[i]-type_I_mmds_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_I_threshs_pre[i]-type_I_threshs_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_I_threshs_boot_pre[i]-type_I_threshs_boot_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_I_threshs_spectrum_pre[i]-type_I_threshs_spectrum_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_I_threshs_gamma_pre[i]-type_I_threshs_gamma_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_II_mmds_pre[i]-type_II_mmds_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_II_threshs_pre[i]-type_II_threshs_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_II_threshs_boot_pre[i]-type_II_threshs_boot_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_II_threshs_spectrum_pre[i]-type_II_threshs_spectrum_pre[i]), 10E-15);
EXPECT_LE(CMath::abs(type_II_threshs_gamma_pre[i]-type_II_threshs_gamma_pre[i]), 10E-15);
}

/* clean up */
Expand Down

0 comments on commit cb523e3

Please sign in to comment.