SHOGUN
v3.2.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2012-2013 Heiko Strathmann 00008 */ 00009 00010 #include <shogun/statistics/MMDKernelSelectionOpt.h> 00011 #include <shogun/statistics/LinearTimeMMD.h> 00012 #include <shogun/kernel/CombinedKernel.h> 00013 00014 using namespace shogun; 00015 00016 CMMDKernelSelectionOpt::CMMDKernelSelectionOpt() : 00017 CMMDKernelSelection() 00018 { 00019 init(); 00020 } 00021 00022 CMMDKernelSelectionOpt::CMMDKernelSelectionOpt( 00023 CKernelTwoSampleTestStatistic* mmd, float64_t lambda) : 00024 CMMDKernelSelection(mmd) 00025 { 00026 init(); 00027 00028 /* currently, this method is only developed for the linear time MMD */ 00029 REQUIRE(dynamic_cast<CLinearTimeMMD*>(mmd), "%s::%s(): Only " 00030 "CLinearTimeMMD is currently supported! Provided instance is " 00031 "\"%s\"\n", get_name(), get_name(), mmd->get_name()); 00032 00033 m_lambda=lambda; 00034 } 00035 00036 CMMDKernelSelectionOpt::~CMMDKernelSelectionOpt() 00037 { 00038 } 00039 00040 SGVector<float64_t> CMMDKernelSelectionOpt::compute_measures() 00041 { 00042 /* comnpute mmd on all subkernels using the same data. Note that underlying 00043 * kernel was asserted to be a combined one */ 00044 SGVector<float64_t> mmds; 00045 SGVector<float64_t> vars; 00046 ((CLinearTimeMMD*)m_mmd)->compute_statistic_and_variance(mmds, vars, true); 00047 00048 /* we know that the underlying MMD is linear time version, cast is safe */ 00049 SGVector<float64_t> measures(mmds.vlen); 00050 00051 for (index_t i=0; i<measures.vlen; ++i) 00052 measures[i]=mmds[i]/(CMath::sqrt(vars[i])+m_lambda); 00053 00054 return measures; 00055 } 00056 00057 void CMMDKernelSelectionOpt::init() 00058 { 00059 /* set to a sensible standard value that proved to be useful in 00060 * experiments, see NIPS paper */ 00061 m_lambda=1E-5; 00062 }