|
SHOGUN v0.9.3
|
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 "lib/common.h" 00015 #include "kernel/StringKernel.h" 00016 #include "classifier/PluginEstimate.h" 00017 #include "features/StringFeatures.h" 00018 00019 namespace shogun 00020 { 00029 class CSalzbergWordStringKernel: public CStringKernel<uint16_t> 00030 { 00031 public: 00038 CSalzbergWordStringKernel(int32_t size, CPluginEstimate* pie, CLabels* labels=NULL); 00039 00047 CSalzbergWordStringKernel( 00048 CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r, 00049 CPluginEstimate *pie, CLabels* labels=NULL); 00050 00051 virtual ~CSalzbergWordStringKernel(); 00052 00058 void set_prior_probs(float64_t pos_prior_, float64_t neg_prior_) 00059 { 00060 pos_prior=pos_prior_ ; 00061 neg_prior=neg_prior_ ; 00062 if (fabs(pos_prior+neg_prior-1)>1e-6) 00063 SG_WARNING( "priors don't sum to 1: %f+%f-1=%f\n", pos_prior, neg_prior, pos_prior+neg_prior-1) ; 00064 }; 00065 00070 void set_prior_probs_from_labels(CLabels* labels); 00071 00078 virtual bool init(CFeatures* l, CFeatures* r); 00079 00081 virtual void cleanup(); 00082 00087 virtual EKernelType get_kernel_type() { return K_SALZBERG; } 00088 00093 virtual const char* get_name() const { return "Salzberg" ; } 00094 00095 protected: 00104 float64_t compute(int32_t idx_a, int32_t idx_b); 00105 // float64_t compute_slow(int64_t idx_a, int64_t idx_b); 00106 00113 inline int32_t compute_index(int32_t position, uint16_t symbol) 00114 { 00115 return position*num_symbols+symbol; 00116 } 00117 00118 protected: 00120 CPluginEstimate* estimate; 00121 00123 float64_t* mean; 00125 float64_t* variance; 00126 00128 float64_t* sqrtdiag_lhs; 00130 float64_t* sqrtdiag_rhs; 00131 00133 float64_t* ld_mean_lhs; 00135 float64_t* ld_mean_rhs; 00136 00138 int32_t num_params; 00140 int32_t num_symbols; 00142 float64_t sum_m2_s2; 00144 float64_t pos_prior; 00146 float64_t neg_prior; 00148 bool initialized; 00149 }; 00150 } 00151 #endif /* _SALZBERGWORDKERNEL_H__ */