Skip to content

Commit

Permalink
renamed OPTIMIZE_MMD to MAXIMIZE_POWER in kernel selection
Browse files Browse the repository at this point in the history
  • Loading branch information
lambday authored and karlnapf committed Jul 3, 2016
1 parent 598fb90 commit 569f432
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
7 changes: 3 additions & 4 deletions src/shogun/statistical_testing/MMD.cpp
Expand Up @@ -45,7 +45,7 @@
#include <shogun/statistical_testing/internals/KernelManager.h>
#include <shogun/statistical_testing/internals/ComputationManager.h>
#include <shogun/statistical_testing/internals/MaxMeasure.h>
#include <shogun/statistical_testing/internals/OptMeasure.h>
#include <shogun/statistical_testing/internals/MaxTestPower.h>
#include <shogun/statistical_testing/internals/mmd/BiasedFull.h>
#include <shogun/statistical_testing/internals/mmd/UnbiasedFull.h>
#include <shogun/statistical_testing/internals/mmd/UnbiasedIncomplete.h>
Expand Down Expand Up @@ -154,7 +154,6 @@ void CMMD::Self::compute_kernel(ComputationManager& cm, std::vector<CFeatures*>&
{
REQUIRE(kernel->get_kernel_type()!=K_CUSTOM, "Underlying kernel cannot be custom!\n");
cm.num_data(blocks.size());
const auto& dm=owner.get_data_manager();
#pragma omp parallel for
for (size_t i=0; i<blocks.size(); ++i)
{
Expand Down Expand Up @@ -333,9 +332,9 @@ void CMMD::select_kernel(EKernelSelectionMethod kmethod)
get_kernel_manager().kernel_at(0)=policy.select_kernel();
break;
}
case EKernelSelectionMethod::OPTIMIZE_MMD:
case EKernelSelectionMethod::MAXIMIZE_POWER:
{
OptMeasure policy(self->kernel_selection_mgr, this);
MaxTestPower policy(self->kernel_selection_mgr, this);
get_kernel_manager().kernel_at(0)=policy.select_kernel();
break;
}
Expand Down
5 changes: 2 additions & 3 deletions src/shogun/statistical_testing/MMD.h
Expand Up @@ -46,7 +46,7 @@ template <typename> class SGMatrix;
namespace internal
{

class OptMeasure;
class MaxTestPower;

}

Expand Down Expand Up @@ -75,14 +75,13 @@ enum class EKernelSelectionMethod
{
MEDIAN_HEURISRIC,
MAXIMIZE_MMD,
OPTIMIZE_MMD,
MAXIMIZE_POWER
};

class CMMD : public CTwoSampleTest
{
using operation=std::function<float32_t(SGMatrix<float32_t>)>;
friend class internal::OptMeasure;
friend class internal::MaxTestPower;
public:
CMMD();
virtual ~CMMD();
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/statistical_testing/internals/KernelSelection.cpp
Expand Up @@ -34,7 +34,7 @@
#include <shogun/statistical_testing/internals/KernelManager.h>
#include <shogun/statistical_testing/internals/KernelSelection.h>
#include <shogun/statistical_testing/internals/MaxMeasure.h>
#include <shogun/statistical_testing/internals/OptMeasure.h>
#include <shogun/statistical_testing/internals/MaxTestPower.h>

namespace shogun
{
Expand All @@ -55,7 +55,7 @@ CKernel* KernelSelection<Derived>::select_kernel()
}

template class KernelSelection<MaxMeasure>;
template class KernelSelection<OptMeasure>;
template class KernelSelection<MaxTestPower>;

}

Expand Down
Expand Up @@ -34,18 +34,18 @@
#include <shogun/kernel/Kernel.h>
#include <shogun/mathematics/Math.h>
#include <shogun/statistical_testing/MMD.h>
#include <shogun/statistical_testing/internals/OptMeasure.h>
#include <shogun/statistical_testing/internals/MaxTestPower.h>
#include <shogun/statistical_testing/internals/KernelManager.h>

using namespace shogun;
using namespace internal;

OptMeasure::OptMeasure(KernelManager& km, CMMD* est)
: KernelSelection<OptMeasure>(km), estimator(est), lambda(1E-5)
MaxTestPower::MaxTestPower(KernelManager& km, CMMD* est)
: KernelSelection<MaxTestPower>(km), estimator(est), lambda(1E-5)
{
}

SGVector<float64_t> OptMeasure::compute_measures()
SGVector<float64_t> MaxTestPower::compute_measures()
{
SGVector<float64_t> result(kernel_mgr.num_kernels());
for (size_t i=0; i<kernel_mgr.num_kernels(); ++i)
Expand All @@ -59,7 +59,7 @@ SGVector<float64_t> OptMeasure::compute_measures()
return result;
}

CKernel* OptMeasure::select_kernel()
CKernel* MaxTestPower::select_kernel()
{
REQUIRE(estimator!=nullptr, "Estimator is not set!\n");
REQUIRE(kernel_mgr.num_kernels()>0, "Number of kernels is %d!\n", kernel_mgr.num_kernels());
Expand Down
Expand Up @@ -29,8 +29,8 @@
* either expressed or implied, of the Shogun Development Team.
*/

#ifndef OPT_MEASURE_H__
#define OPT_MEASURE_H__
#ifndef MAX_TEST_POWER_H__
#define MAX_TEST_POWER_H__

#include <shogun/lib/common.h>
#include <shogun/statistical_testing/internals/KernelSelection.h>
Expand All @@ -45,12 +45,12 @@ template <typename T> class SGVector;
namespace internal
{

class OptMeasure : public KernelSelection<OptMeasure>
class MaxTestPower : public KernelSelection<MaxTestPower>
{
public:
OptMeasure(KernelManager&, CMMD*);
OptMeasure(const OptMeasure& other)=delete;
OptMeasure& operator=(const OptMeasure& other)=delete;
MaxTestPower(KernelManager&, CMMD*);
MaxTestPower(const MaxTestPower& other)=delete;
MaxTestPower& operator=(const MaxTestPower& other)=delete;
CKernel* select_kernel();
protected:
SGVector<float64_t> compute_measures();
Expand All @@ -62,4 +62,4 @@ class OptMeasure : public KernelSelection<OptMeasure>

}

#endif // OPT_MEASURE_H__
#endif // MAX_TEST_POWER_H__
Expand Up @@ -72,7 +72,7 @@ TEST(KernelSelectionOptMMD, perform_test_permutation_biased_full)
mmd->add_kernel(new CGaussianKernel(10, sq_sigma_twice));
}

mmd->select_kernel(EKernelSelectionMethod::OPTIMIZE_MMD);
mmd->select_kernel(EKernelSelectionMethod::MAXIMIZE_POWER);
auto selected_kernel=static_cast<CGaussianKernel*>(mmd->get_kernel());
EXPECT_NEAR(selected_kernel->get_width(), 0.5, 1E-10);

Expand Down Expand Up @@ -118,7 +118,7 @@ TEST(KernelSelectionOptMMD, perform_test_permutation_unbiased_full)
mmd->add_kernel(new CGaussianKernel(10, sq_sigma_twice));
}

mmd->select_kernel(EKernelSelectionMethod::OPTIMIZE_MMD);
mmd->select_kernel(EKernelSelectionMethod::MAXIMIZE_POWER);
auto selected_kernel=static_cast<CGaussianKernel*>(mmd->get_kernel());
EXPECT_NEAR(selected_kernel->get_width(), 0.5, 1E-10);

Expand Down Expand Up @@ -164,7 +164,7 @@ TEST(KernelSelectionOptMMD, perform_test_permutation_unbiased_incomplete)
mmd->add_kernel(new CGaussianKernel(10, sq_sigma_twice));
}

mmd->select_kernel(EKernelSelectionMethod::OPTIMIZE_MMD);
mmd->select_kernel(EKernelSelectionMethod::MAXIMIZE_POWER);
auto selected_kernel=static_cast<CGaussianKernel*>(mmd->get_kernel());
EXPECT_NEAR(selected_kernel->get_width(), 0.5, 1E-10);

Expand Down

0 comments on commit 569f432

Please sign in to comment.