50 using namespace internal;
57 std::unique_ptr<KernelSelection>
policy;
65 void init_policy(
CMMD* estimator);
81 weighted(default_weighted), num_runs(default_num_runs), num_folds(default_num_folds), alpha(default_alpha)
91 REQUIRE(!
weighted,
"Weighted kernel selection is not possible with MEDIAN_HEURISTIC!\n");
92 policy=std::unique_ptr<MedianHeuristic>(
new MedianHeuristic(
kernel_mgr, estimator));
97 REQUIRE(!
weighted,
"Weighted kernel selection is not possible with CROSS_VALIDATION!\n");
98 policy=std::unique_ptr<MaxCrossValidation>(
new MaxCrossValidation(
kernel_mgr, estimator,
105 policy=std::unique_ptr<WeightedMaxMeasure>(
new WeightedMaxMeasure(
kernel_mgr, estimator));
114 auto casted_estimator=
dynamic_cast<CStreamingMMD*
>(estimator);
115 REQUIRE(casted_estimator,
"Weighted kernel selection is not possible with MAXIMIZE_POWER!\n");
116 policy=std::unique_ptr<WeightedMaxTestPower>(
new WeightedMaxTestPower(
kernel_mgr, estimator));
119 policy=std::unique_ptr<MaxTestPower>(
new MaxTestPower(
kernel_mgr, estimator));
124 SG_SERROR(
"Unsupported kernel selection method specified! Accepted strategies are " 125 "MAXIMIZE_MMD (single, weighted), " 126 "MAXIMIZE_POWER (single, weighted), " 127 "CROSS_VALIDATION (single) and " 128 "MEDIAN_HEURISTIC (single)!\n");
134 CKernelSelectionStrategy::CKernelSelectionStrategy()
156 void CKernelSelectionStrategy::init()
158 self=std::unique_ptr<Self>(
new Self());
161 CKernelSelectionStrategy::~CKernelSelectionStrategy()
163 self->kernel_mgr.clear();
201 index_t CKernelSelectionStrategy::get_num_runs()
const 203 return self->num_runs;
206 index_t CKernelSelectionStrategy::get_num_folds()
const 208 return self->num_folds;
211 float64_t CKernelSelectionStrategy::get_alpha()
const 216 bool CKernelSelectionStrategy::get_weighted()
const 218 return self->weighted;
221 void CKernelSelectionStrategy::add_kernel(
CKernel* kernel)
223 self->kernel_mgr.push_back(kernel);
226 CKernel* CKernelSelectionStrategy::select_kernel(
CMMD* estimator)
228 auto num_kernels=
self->kernel_mgr.num_kernels();
229 REQUIRE(num_kernels>0,
"Number of kernels is 0. Please add kernels using add_kernel method!\n");
230 SG_DEBUG(
"Selecting kernels from a total of %d kernels!\n", num_kernels);
232 self->init_policy(estimator);
233 ASSERT(self->policy!=
nullptr);
235 return self->policy->select_kernel();
239 void CKernelSelectionStrategy::erase_intermediate_results()
241 self->policy=
nullptr;
242 self->kernel_mgr.clear();
247 REQUIRE(self->policy!=
nullptr,
"The kernel selection policy is not initialized!\n");
248 return self->policy->get_measure_matrix();
253 REQUIRE(self->policy!=
nullptr,
"The kernel selection policy is not initialized!\n");
254 return self->policy->get_measure_vector();
257 const char* CKernelSelectionStrategy::get_name()
const 259 return "KernelSelectionStrategy";
262 const KernelManager& CKernelSelectionStrategy::get_kernel_mgr()
const 264 return self->kernel_mgr;
static const index_t default_num_runs
EKernelSelectionMethod method
static const index_t default_num_folds
static const EKernelSelectionMethod default_method
std::unique_ptr< KernelSelection > policy
all of classes and functions are contained in the shogun namespace
static const float64_t default_alpha
Abstract base class that provides an interface for performing kernel two-sample test using Maximum Me...
void init_policy(CMMD *estimator)
static const bool default_weighted