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 Heiko Strathmann 00008 */ 00009 00010 #ifndef __LINEARTIMEMMD_H_ 00011 #define __LINEARTIMEMMD_H_ 00012 00013 #include <shogun/statistics/KernelTwoSampleTestStatistic.h> 00014 #include <shogun/kernel/Kernel.h> 00015 #include <shogun/lib/external/libqp.h> 00016 00017 namespace shogun 00018 { 00019 00020 class CStreamingFeatures; 00021 class CFeatures; 00022 00085 class CLinearTimeMMD: public CKernelTwoSampleTestStatistic 00086 { 00087 public: 00088 CLinearTimeMMD(); 00089 00099 CLinearTimeMMD(CKernel* kernel, CStreamingFeatures* p, 00100 CStreamingFeatures* q, index_t m, index_t blocksize=10000); 00101 00102 virtual ~CLinearTimeMMD(); 00103 00112 virtual float64_t compute_statistic(); 00113 00127 virtual float64_t compute_p_value(float64_t statistic); 00128 00144 virtual float64_t perform_test(); 00145 00158 virtual float64_t compute_threshold(float64_t alpha); 00159 00167 virtual float64_t compute_variance_estimate(); 00168 00175 virtual void compute_statistic_and_variance(float64_t& statistic, 00176 float64_t& variance); 00177 00187 virtual SGVector<float64_t> bootstrap_null(); 00188 00189 #ifdef HAVE_LAPACK 00190 00206 virtual void optimize_kernel_weights(); 00207 00209 void set_opt_max_iterations(index_t opt_max_iterations) 00210 { 00211 m_opt_max_iterations=opt_max_iterations; 00212 } 00213 00215 void set_opt_epsilon(float64_t opt_epsilon) { 00216 m_opt_epsilon=opt_epsilon; 00217 } 00218 00221 void set_opt_low_cut(float64_t opt_low_cut) 00222 { 00223 m_opt_low_cut=opt_low_cut; 00224 } 00225 00228 void set_opt_regularization_eps(float64_t opt_regularization_eps) 00229 { 00230 m_opt_regularization_eps=opt_regularization_eps; 00231 } 00232 #endif //HAVE_LAPACK 00233 00234 virtual const char* get_name() const 00235 { 00236 return "LinearTimeMMD"; 00237 } 00238 00239 private: 00240 void init(); 00241 00242 public: 00243 #ifdef HAVE_LAPACK 00244 00245 static const float64_t* get_Q_col(uint32_t i); 00246 00248 static void print_state(libqp_state_T state); 00249 #endif //HAVE_LAPACK 00250 00251 protected: 00253 CStreamingFeatures* m_streaming_p; 00254 00256 CStreamingFeatures* m_streaming_q; 00257 00259 index_t m_blocksize; 00260 00261 #ifdef HAVE_LAPACK 00262 00263 index_t m_opt_max_iterations; 00264 00266 float64_t m_opt_epsilon; 00267 00269 float64_t m_opt_low_cut; 00270 00272 float64_t m_opt_regularization_eps; 00273 00275 static SGMatrix<float64_t> m_Q; 00276 #endif //HAVE_LAPACK 00277 00278 }; 00279 00280 } 00281 00282 #endif /* __LINEARTIMEMMD_H_ */ 00283