diff --git a/src/shogun/statistical_testing/BTestMMD.cpp b/src/shogun/statistical_testing/BTestMMD.cpp index cacc801c5db..7abfa4d0343 100644 --- a/src/shogun/statistical_testing/BTestMMD.cpp +++ b/src/shogun/statistical_testing/BTestMMD.cpp @@ -73,7 +73,7 @@ float64_t CBTestMMD::compute_p_value(float64_t statistic) float64_t result=0; switch (get_null_approximation_method()) { - case NAM_MMD1_GAUSSIAN: + case ENullApproximationMethod::NAM_MMD1_GAUSSIAN: { float64_t sigma_sq=compute_variance(); float64_t std_dev=CMath::sqrt(sigma_sq); @@ -94,7 +94,7 @@ float64_t CBTestMMD::compute_threshold(float64_t alpha) float64_t result=0; switch (get_null_approximation_method()) { - case NAM_MMD1_GAUSSIAN: + case ENullApproximationMethod::NAM_MMD1_GAUSSIAN: { float64_t sigma_sq=compute_variance(); float64_t std_dev=CMath::sqrt(sigma_sq); diff --git a/src/shogun/statistical_testing/LinearTimeMMD.cpp b/src/shogun/statistical_testing/LinearTimeMMD.cpp index 927dcf5961e..a41a2059408 100644 --- a/src/shogun/statistical_testing/LinearTimeMMD.cpp +++ b/src/shogun/statistical_testing/LinearTimeMMD.cpp @@ -83,7 +83,7 @@ const float64_t CLinearTimeMMD::normalize_variance(float64_t variance) const const index_t Bx = data_mgr.blocksize_at(0); const index_t By = data_mgr.blocksize_at(1); const index_t B = Bx + By; - if (get_statistic_type() == ST_UNBIASED_INCOMPLETE) + if (get_statistic_type() == EStatisticType::ST_UNBIASED_INCOMPLETE) { return variance * B * (B - 2) / 16; } @@ -96,7 +96,7 @@ const float64_t CLinearTimeMMD::gaussian_variance(float64_t variance) const const index_t Bx = data_mgr.blocksize_at(0); const index_t By = data_mgr.blocksize_at(1); const index_t B = Bx + By; - if (get_statistic_type() == ST_UNBIASED_INCOMPLETE) + if (get_statistic_type() == EStatisticType::ST_UNBIASED_INCOMPLETE) { return variance * 4 / (B - 2); } @@ -108,7 +108,7 @@ float64_t CLinearTimeMMD::compute_p_value(float64_t statistic) float64_t result = 0; switch (get_null_approximation_method()) { - case NAM_MMD1_GAUSSIAN: + case ENullApproximationMethod::NAM_MMD1_GAUSSIAN: { float64_t sigma_sq = gaussian_variance(compute_variance()); float64_t std_dev = CMath::sqrt(sigma_sq); @@ -129,7 +129,7 @@ float64_t CLinearTimeMMD::compute_threshold(float64_t alpha) float64_t result = 0; switch (get_null_approximation_method()) { - case NAM_MMD1_GAUSSIAN: + case ENullApproximationMethod::NAM_MMD1_GAUSSIAN: { float64_t sigma_sq = gaussian_variance(compute_variance()); float64_t std_dev = CMath::sqrt(sigma_sq); diff --git a/src/shogun/statistical_testing/MMD.cpp b/src/shogun/statistical_testing/MMD.cpp index cdfe0b04ff0..03ba00fea28 100644 --- a/src/shogun/statistical_testing/MMD.cpp +++ b/src/shogun/statistical_testing/MMD.cpp @@ -89,9 +89,9 @@ struct CMMD::Self CMMD::Self::Self(CMMD& cmmd) : owner(cmmd), use_gpu(false), num_null_samples(250), - statistic_type(ST_UNBIASED_FULL), - variance_estimation_method(VEM_DIRECT), - null_approximation_method(NAM_PERMUTATION), + statistic_type(EStatisticType::ST_UNBIASED_FULL), + variance_estimation_method(EVarianceEstimationMethod::VEM_DIRECT), + null_approximation_method(ENullApproximationMethod::NAM_PERMUTATION), statistic_job(nullptr), variance_job(nullptr) { auto default_strategy=new CKernelSelectionStrategy(); @@ -112,13 +112,13 @@ void CMMD::Self::create_statistic_job() auto By=data_mgr.blocksize_at(1); switch (statistic_type) { - case ST_UNBIASED_FULL: + case EStatisticType::ST_UNBIASED_FULL: statistic_job=mmd::UnbiasedFull(Bx); break; - case ST_UNBIASED_INCOMPLETE: + case EStatisticType::ST_UNBIASED_INCOMPLETE: statistic_job=mmd::UnbiasedIncomplete(Bx); break; - case ST_BIASED_FULL: + case EStatisticType::ST_BIASED_FULL: statistic_job=mmd::BiasedFull(Bx); break; default : break; @@ -130,10 +130,10 @@ void CMMD::Self::create_variance_job() { switch (variance_estimation_method) { - case VEM_DIRECT: + case EVarianceEstimationMethod::VEM_DIRECT: variance_job=owner.get_direct_estimation_method(); break; - case VEM_PERMUTATION: + case EVarianceEstimationMethod::VEM_PERMUTATION: variance_job=permutation_job; break; default : break; @@ -223,7 +223,7 @@ std::pair CMMD::Self::compute_statistic_variance() statistic_term_counter++; } - if (variance_estimation_method==VEM_DIRECT) + if (variance_estimation_method==EVarianceEstimationMethod::VEM_DIRECT) { for (size_t i=0; i CMMD::Self::compute_statistic_variance() // normalize statistic and variance statistic=owner.normalize_statistic(statistic); - if (variance_estimation_method==VEM_PERMUTATION) + if (variance_estimation_method==EVarianceEstimationMethod::VEM_PERMUTATION) variance=owner.normalize_variance(variance); return std::make_pair(statistic, variance); diff --git a/src/shogun/statistical_testing/MMD.h b/src/shogun/statistical_testing/MMD.h index c57bf3ccb9d..389e0f8872f 100644 --- a/src/shogun/statistical_testing/MMD.h +++ b/src/shogun/statistical_testing/MMD.h @@ -43,7 +43,7 @@ class CKernel; template class SGVector; template class SGMatrix; class CKernelSelectionStrategy; -enum EKernelSelectionMethod : uint32_t; +enum class EKernelSelectionMethod; namespace internal { @@ -55,20 +55,20 @@ class WeightedMaxTestPower; } -enum EStatisticType : uint32_t +enum class EStatisticType { ST_UNBIASED_FULL, ST_UNBIASED_INCOMPLETE, ST_BIASED_FULL }; -enum EVarianceEstimationMethod : uint32_t +enum class EVarianceEstimationMethod { VEM_DIRECT, VEM_PERMUTATION }; -enum ENullApproximationMethod : uint32_t +enum class ENullApproximationMethod { NAM_PERMUTATION, NAM_MMD1_GAUSSIAN, diff --git a/src/shogun/statistical_testing/QuadraticTimeMMD.cpp b/src/shogun/statistical_testing/QuadraticTimeMMD.cpp index b4a66cdeb5a..5b904a8633c 100644 --- a/src/shogun/statistical_testing/QuadraticTimeMMD.cpp +++ b/src/shogun/statistical_testing/QuadraticTimeMMD.cpp @@ -102,13 +102,13 @@ void CQuadraticTimeMMD::Self::create_statistic_job() auto Nx=data_mgr.num_samples_at(0); switch (owner.get_statistic_type()) { - case ST_UNBIASED_FULL: + case EStatisticType::ST_UNBIASED_FULL: statistic_job=UnbiasedFull(Nx); break; - case ST_UNBIASED_INCOMPLETE: + case EStatisticType::ST_UNBIASED_INCOMPLETE: statistic_job=UnbiasedIncomplete(Nx); break; - case ST_BIASED_FULL: + case EStatisticType::ST_BIASED_FULL: statistic_job=BiasedFull(Nx); break; default : break; @@ -121,10 +121,10 @@ void CQuadraticTimeMMD::Self::create_variance_job() SG_SDEBUG("Entering\n"); switch (owner.get_variance_estimation_method()) { - case VEM_DIRECT: + case EVarianceEstimationMethod::VEM_DIRECT: variance_job=owner.get_direct_estimation_method(); break; - case VEM_PERMUTATION: + case EVarianceEstimationMethod::VEM_PERMUTATION: SG_SERROR("Permutation method is not allowed with Quadratic Time MMD!\n"); break; default : break; @@ -339,7 +339,7 @@ float64_t CQuadraticTimeMMD::compute_p_value(float64_t statistic) float64_t result=0; switch (get_null_approximation_method()) { - case NAM_MMD2_GAMMA: + case ENullApproximationMethod::NAM_MMD2_GAMMA: { SGVector params=gamma_fit_null(); result=CStatistics::gamma_cdf(statistic, params[0], params[1]); @@ -359,7 +359,7 @@ float64_t CQuadraticTimeMMD::compute_threshold(float64_t alpha) float64_t result=0; switch (get_null_approximation_method()) { - case NAM_MMD2_GAMMA: + case ENullApproximationMethod::NAM_MMD2_GAMMA: { SGVector params=gamma_fit_null(); result=CStatistics::gamma_inverse_cdf(alpha, params[0], params[1]); @@ -379,7 +379,7 @@ SGVector CQuadraticTimeMMD::sample_null() SGVector null_samples; switch (get_null_approximation_method()) { - case NAM_MMD2_SPECTRUM: + case ENullApproximationMethod::NAM_MMD2_SPECTRUM: null_samples=spectrum_sample_null(); break; default: @@ -401,7 +401,7 @@ SGVector CQuadraticTimeMMD::gamma_fit_null() REQUIRE(m==n, "Number of samples from p (%d) and q (%d) must be equal.\n", n, m) /* evtl. warn user not to use wrong statistic type */ - if (get_statistic_type()!=ST_BIASED_FULL) + if (get_statistic_type()!=EStatisticType::ST_BIASED_FULL) { SG_WARNING("Note: provided statistic has to be BIASED. Please ensure that! " "To get rid of warning, call %s::set_statistic_type(EStatisticType::BIASED_FULL)\n", get_name()); @@ -515,7 +515,7 @@ SGVector CQuadraticTimeMMD::spectrum_sample_null() float64_t eigenvalue_estimate=eigen_solver.eigenvalues()[max_num_eigenvalues-1-j]; eigenvalue_estimate/=(m+n); - if (get_statistic_type()==ST_UNBIASED_FULL) + if (get_statistic_type()==EStatisticType::ST_UNBIASED_FULL) multiple-=1; null_sample+=eigenvalue_estimate*multiple; diff --git a/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.cpp b/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.cpp index ad55b6acfa4..0d2766d2cbc 100644 --- a/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.cpp +++ b/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.cpp @@ -104,7 +104,7 @@ float64_t MultiKernelPermutationTestCrossValidation::compute_mmd(terms_t& terms) terms.term[1]=2*(terms.term[1]-terms.diag[1]); SG_SDEBUG("term_0 sum (without diagonal) = %f!\n", terms.term[0]); SG_SDEBUG("term_1 sum (without diagonal) = %f!\n", terms.term[1]); - if (stype!=ST_BIASED_FULL) + if (stype!=EStatisticType::ST_BIASED_FULL) { terms.term[0]/=n_x*(n_x-1); terms.term[1]/=n_y*(n_y-1); @@ -122,7 +122,7 @@ float64_t MultiKernelPermutationTestCrossValidation::compute_mmd(terms_t& terms) SG_SDEBUG("term_1 (normalized) = %f!\n", terms.term[1]); SG_SDEBUG("term_2 sum (with diagonal) = %f!\n", terms.term[2]); - if (stype==ST_UNBIASED_INCOMPLETE) + if (stype==EStatisticType::ST_UNBIASED_INCOMPLETE) { terms.term[2]-=terms.diag[2]; SG_SDEBUG("term_2 sum (without diagonal) = %f!\n", terms.term[2]); diff --git a/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.h b/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.h index add0ace9085..f58235ba96a 100644 --- a/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.h +++ b/src/shogun/statistical_testing/internals/mmd/MultiKernelPermutationTestCrossValidation.h @@ -38,7 +38,7 @@ namespace shogun { -enum EStatisticType : uint32_t; +enum class EStatisticType; class CCustomDistance; namespace internal diff --git a/src/shogun/statistical_testing/internals/mmd/PermutationTestCrossValidation.cpp b/src/shogun/statistical_testing/internals/mmd/PermutationTestCrossValidation.cpp index e52f3806926..434ecd1664b 100644 --- a/src/shogun/statistical_testing/internals/mmd/PermutationTestCrossValidation.cpp +++ b/src/shogun/statistical_testing/internals/mmd/PermutationTestCrossValidation.cpp @@ -110,7 +110,7 @@ float64_t PermutationTestCrossValidation::compute_mmd(terms_t& terms) terms.term[1]=2*(terms.term[1]-terms.diag[1]); SG_SDEBUG("term_0 sum (without diagonal) = %f!\n", terms.term[0]); SG_SDEBUG("term_1 sum (without diagonal) = %f!\n", terms.term[1]); - if (stype!=ST_BIASED_FULL) + if (stype!=EStatisticType::ST_BIASED_FULL) { terms.term[0]/=n_x*(n_x-1); terms.term[1]/=n_y*(n_y-1); @@ -128,7 +128,7 @@ float64_t PermutationTestCrossValidation::compute_mmd(terms_t& terms) SG_SDEBUG("term_1 (normalized) = %f!\n", terms.term[1]); SG_SDEBUG("term_2 sum (with diagonal) = %f!\n", terms.term[2]); - if (stype==ST_UNBIASED_INCOMPLETE) + if (stype==EStatisticType::ST_UNBIASED_INCOMPLETE) { terms.term[2]-=terms.diag[2]; SG_SDEBUG("term_2 sum (without diagonal) = %f!\n", terms.term[2]); diff --git a/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutation.cpp b/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutation.cpp index 4ec59f73de4..3bd1ef3f064 100644 --- a/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutation.cpp +++ b/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutation.cpp @@ -85,7 +85,7 @@ float32_t WithinBlockPermutation::operator()(const SGMatrix& km) terms.term[1]=2*(terms.term[1]-terms.diag[1]); SG_SDEBUG("term_0 sum (without diagonal) = %f!\n", terms.term[0]); SG_SDEBUG("term_1 sum (without diagonal) = %f!\n", terms.term[1]); - if (stype!=ST_BIASED_FULL) + if (stype!=EStatisticType::ST_BIASED_FULL) { terms.term[0]/=n_x*(n_x-1); terms.term[1]/=n_y*(n_y-1); @@ -103,7 +103,7 @@ float32_t WithinBlockPermutation::operator()(const SGMatrix& km) SG_SDEBUG("term_1 (normalized) = %f!\n", terms.term[1]); SG_SDEBUG("term_2 sum (with diagonal) = %f!\n", terms.term[2]); - if (stype==ST_UNBIASED_INCOMPLETE) + if (stype==EStatisticType::ST_UNBIASED_INCOMPLETE) { terms.term[2]-=terms.diag[2]; SG_SDEBUG("term_2 sum (without diagonal) = %f!\n", terms.term[2]); diff --git a/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutationBatch.cpp b/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutationBatch.cpp index 311d17cf9e1..bd0ae7d7ade 100644 --- a/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutationBatch.cpp +++ b/src/shogun/statistical_testing/internals/mmd/WithinBlockPermutationBatch.cpp @@ -102,7 +102,7 @@ SGVector WithinBlockPermutationBatch::operator()(const Kernel& km) t.term[1]=2*(t.term[1]-t.diag[1]); SG_SDEBUG("term_0 sum (without diagonal) = %f!\n", t.term[0]); SG_SDEBUG("term_1 sum (without diagonal) = %f!\n", t.term[1]); - if (stype!=ST_BIASED_FULL) + if (stype!=EStatisticType::ST_BIASED_FULL) { t.term[0]/=n_x*(n_x-1); t.term[1]/=n_y*(n_y-1); @@ -120,7 +120,7 @@ SGVector WithinBlockPermutationBatch::operator()(const Kernel& km) SG_SDEBUG("term_1 (normalized) = %f!\n", t.term[1]); SG_SDEBUG("term_2 sum (with diagonal) = %f!\n", t.term[2]); - if (stype==ST_UNBIASED_INCOMPLETE) + if (stype==EStatisticType::ST_UNBIASED_INCOMPLETE) { t.term[2]-=t.diag[2]; SG_SDEBUG("term_2 sum (without diagonal) = %f!\n", t.term[2]); diff --git a/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.cpp b/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.cpp index fcb31f89e3f..5dd6aa157da 100644 --- a/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.cpp +++ b/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.cpp @@ -69,7 +69,7 @@ struct CKernelSelectionStrategy::Self const static float64_t default_alpha; }; -const EKernelSelectionMethod CKernelSelectionStrategy::Self::default_method=KSM_AUTO; +const EKernelSelectionMethod CKernelSelectionStrategy::Self::default_method=EKernelSelectionMethod::KSM_AUTO; const bool CKernelSelectionStrategy::Self::default_weighted=false; const index_t CKernelSelectionStrategy::Self::default_num_runs=10; const index_t CKernelSelectionStrategy::Self::default_num_folds=3; @@ -84,20 +84,20 @@ void CKernelSelectionStrategy::Self::init_policy(CMMD* estimator) { switch (method) { - case KSM_MEDIAN_HEURISTIC: + case EKernelSelectionMethod::KSM_MEDIAN_HEURISTIC: { REQUIRE(!weighted, "Weighted kernel selection is not possible with MEDIAN_HEURISTIC!\n"); policy=std::unique_ptr(new MedianHeuristic(kernel_mgr, estimator)); } break; - case KSM_MAXIMIZE_CROSS_VALIDATION: + case EKernelSelectionMethod::KSM_MAXIMIZE_CROSS_VALIDATION: { REQUIRE(!weighted, "Weighted kernel selection is not possible with MAXIMIZE_CROSS_VALIDATION!\n"); policy=std::unique_ptr(new MaxCrossValidation(kernel_mgr, estimator, num_runs, num_folds, alpha)); } break; - case KSM_MAXIMIZE_MMD: + case EKernelSelectionMethod::KSM_MAXIMIZE_MMD: { if (weighted) policy=std::unique_ptr(new WeightedMaxMeasure(kernel_mgr, estimator)); @@ -105,7 +105,7 @@ void CKernelSelectionStrategy::Self::init_policy(CMMD* estimator) policy=std::unique_ptr(new MaxMeasure(kernel_mgr, estimator)); } break; - case KSM_MAXIMIZE_POWER: + case EKernelSelectionMethod::KSM_MAXIMIZE_POWER: { if (weighted) policy=std::unique_ptr(new WeightedMaxTestPower(kernel_mgr, estimator)); diff --git a/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.h b/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.h index 3de5b38ad96..2b497ddeac0 100644 --- a/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.h +++ b/src/shogun/statistical_testing/kernelselection/KernelSelectionStrategy.h @@ -49,7 +49,7 @@ namespace internal class KernelManager; } -enum EKernelSelectionMethod : uint32_t +enum class EKernelSelectionMethod { KSM_MEDIAN_HEURISTIC, KSM_MAXIMIZE_MMD,