SHOGUN
v2.0.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) 1999-2008 Gunnar Raetsch 00008 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _SALZBERGWORDSTRINGKERNEL_H___ 00012 #define _SALZBERGWORDSTRINGKERNEL_H___ 00013 00014 #include <shogun/lib/common.h> 00015 #include <shogun/kernel/string/StringKernel.h> 00016 #include <shogun/classifier/PluginEstimate.h> 00017 #include <shogun/features/StringFeatures.h> 00018 00019 namespace shogun 00020 { 00029 class CSalzbergWordStringKernel: public CStringKernel<uint16_t> 00030 { 00031 public: 00033 CSalzbergWordStringKernel(); 00034 00041 CSalzbergWordStringKernel(int32_t size, CPluginEstimate* pie, CLabels* labels=NULL); 00042 00050 CSalzbergWordStringKernel( 00051 CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r, 00052 CPluginEstimate *pie, CLabels* labels=NULL); 00053 00054 virtual ~CSalzbergWordStringKernel(); 00055 00061 void set_prior_probs(float64_t pos_prior_, float64_t neg_prior_) 00062 { 00063 pos_prior=pos_prior_ ; 00064 neg_prior=neg_prior_ ; 00065 if (fabs(pos_prior+neg_prior-1)>1e-6) 00066 SG_WARNING( "priors don't sum to 1: %f+%f-1=%f\n", pos_prior, neg_prior, pos_prior+neg_prior-1) ; 00067 }; 00068 00073 void set_prior_probs_from_labels(CLabels* labels); 00074 00081 virtual bool init(CFeatures* l, CFeatures* r); 00082 00084 virtual void cleanup(); 00085 00090 virtual EKernelType get_kernel_type() { return K_SALZBERG; } 00091 00096 virtual const char* get_name() const { return "SalzbergWordStringKernel" ; } 00097 00098 protected: 00107 float64_t compute(int32_t idx_a, int32_t idx_b); 00108 // float64_t compute_slow(int64_t idx_a, int64_t idx_b); 00109 00116 inline int32_t compute_index(int32_t position, uint16_t symbol) 00117 { 00118 return position*num_symbols+symbol; 00119 } 00120 private: 00121 void init(); 00122 00123 protected: 00125 CPluginEstimate* estimate; 00126 00128 float64_t* mean; 00130 float64_t* variance; 00131 00133 float64_t* sqrtdiag_lhs; 00135 float64_t* sqrtdiag_rhs; 00136 00138 float64_t* ld_mean_lhs; 00140 float64_t* ld_mean_rhs; 00141 00143 int32_t num_params; 00145 int32_t num_symbols; 00147 float64_t sum_m2_s2; 00149 float64_t pos_prior; 00151 float64_t neg_prior; 00153 bool initialized; 00154 }; 00155 } 00156 #endif /* _SALZBERGWORDKERNEL_H__ */