Skip to content

Commit

Permalink
make all enums be classes
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 4, 2016
1 parent 78c3c8c commit 1a8d7a4
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/shogun/statistical_testing/BTestMMD.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/shogun/statistical_testing/LinearTimeMMD.cpp
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions src/shogun/statistical_testing/MMD.cpp
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -223,7 +223,7 @@ std::pair<float64_t, float64_t> 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<mmds.size(); ++i)
{
Expand All @@ -250,7 +250,7 @@ std::pair<float64_t, float64_t> 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);
Expand Down
8 changes: 4 additions & 4 deletions src/shogun/statistical_testing/MMD.h
Expand Up @@ -43,7 +43,7 @@ class CKernel;
template <typename> class SGVector;
template <typename> class SGMatrix;
class CKernelSelectionStrategy;
enum EKernelSelectionMethod : uint32_t;
enum class EKernelSelectionMethod;

namespace internal
{
Expand All @@ -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,
Expand Down
20 changes: 10 additions & 10 deletions src/shogun/statistical_testing/QuadraticTimeMMD.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<float64_t> params=gamma_fit_null();
result=CStatistics::gamma_cdf(statistic, params[0], params[1]);
Expand All @@ -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<float64_t> params=gamma_fit_null();
result=CStatistics::gamma_inverse_cdf(alpha, params[0], params[1]);
Expand All @@ -379,7 +379,7 @@ SGVector<float64_t> CQuadraticTimeMMD::sample_null()
SGVector<float64_t> null_samples;
switch (get_null_approximation_method())
{
case NAM_MMD2_SPECTRUM:
case ENullApproximationMethod::NAM_MMD2_SPECTRUM:
null_samples=spectrum_sample_null();
break;
default:
Expand All @@ -401,7 +401,7 @@ SGVector<float64_t> 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());
Expand Down Expand Up @@ -515,7 +515,7 @@ SGVector<float64_t> 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;
Expand Down
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down
Expand Up @@ -38,7 +38,7 @@
namespace shogun
{

enum EStatisticType : uint32_t;
enum class EStatisticType;
class CCustomDistance;

namespace internal
Expand Down
Expand Up @@ -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);
Expand All @@ -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]);
Expand Down
Expand Up @@ -85,7 +85,7 @@ float32_t WithinBlockPermutation::operator()(const SGMatrix<float32_t>& 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);
Expand All @@ -103,7 +103,7 @@ float32_t WithinBlockPermutation::operator()(const SGMatrix<float32_t>& 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]);
Expand Down
Expand Up @@ -102,7 +102,7 @@ SGVector<float32_t> 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);
Expand All @@ -120,7 +120,7 @@ SGVector<float32_t> 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]);
Expand Down
Expand Up @@ -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;
Expand All @@ -84,28 +84,28 @@ 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<MedianHeuristic>(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<MaxCrossValidation>(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<WeightedMaxMeasure>(new WeightedMaxMeasure(kernel_mgr, estimator));
else
policy=std::unique_ptr<MaxMeasure>(new MaxMeasure(kernel_mgr, estimator));
}
break;
case KSM_MAXIMIZE_POWER:
case EKernelSelectionMethod::KSM_MAXIMIZE_POWER:
{
if (weighted)
policy=std::unique_ptr<WeightedMaxTestPower>(new WeightedMaxTestPower(kernel_mgr, estimator));
Expand Down
Expand Up @@ -49,7 +49,7 @@ namespace internal
class KernelManager;
}

enum EKernelSelectionMethod : uint32_t
enum class EKernelSelectionMethod
{
KSM_MEDIAN_HEURISTIC,
KSM_MAXIMIZE_MMD,
Expand Down

0 comments on commit 1a8d7a4

Please sign in to comment.