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) 1999-2009 Soeren Sonnenburg 00008 * Written (W) 1999-2008 Gunnar Raetsch 00009 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00010 */ 00011 00012 #ifndef _SPECTRUMMISMATCHRBFKERNEL_H___ 00013 #define _SPECTRUMMISMATCHRBFKERNEL_H___ 00014 00015 #include <shogun/lib/common.h> 00016 #include <shogun/lib/Trie.h> 00017 #include <shogun/kernel/string/StringKernel.h> 00018 #include <shogun/features/StringFeatures.h> 00019 00020 #include <shogun/lib/DynamicArray.h> 00021 #include <string> 00022 #include <vector> 00023 00024 namespace shogun 00025 { 00026 00027 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00028 00029 struct joint_list_struct 00030 { 00032 unsigned int ex_index; 00034 unsigned int index; 00036 unsigned int mismatch; 00037 }; 00038 #endif 00039 00041 class CSpectrumMismatchRBFKernel: public CStringKernel<char> 00042 { 00043 public: 00045 CSpectrumMismatchRBFKernel(); 00046 00057 CSpectrumMismatchRBFKernel(int32_t size, float64_t* AA_matrix_, int32_t nr_, 00058 int32_t nc_, int32_t degree, int32_t max_mismatch, float64_t width); 00059 00072 CSpectrumMismatchRBFKernel(CStringFeatures<char>* l, 00073 CStringFeatures<char>* r, int32_t size, float64_t* AA_matrix_, 00074 int32_t nr_, int32_t nc_, int32_t degree, int32_t max_mismatch, 00075 float64_t width); 00076 00078 virtual ~CSpectrumMismatchRBFKernel(); 00079 00086 virtual bool init(CFeatures* l, CFeatures* r); 00087 00089 virtual void cleanup(); 00090 00095 virtual EKernelType get_kernel_type() 00096 { 00097 return K_SPECTRUMMISMATCHRBF; 00098 } 00099 00104 virtual const char* get_name() const 00105 { 00106 return "SpectrumMismatchRBFKernel"; 00107 } 00108 00114 bool set_max_mismatch(int32_t max); 00115 00120 inline int32_t get_max_mismatch() const 00121 { 00122 return max_mismatch; 00123 } 00124 00130 inline bool set_degree(int32_t deg) 00131 { 00132 degree=deg; 00133 return true; 00134 } 00135 00140 inline int32_t get_degree() const 00141 { 00142 return degree; 00143 } 00144 00151 bool set_AA_matrix(float64_t* AA_matrix_=NULL, int32_t nr=128, int32_t nc= 00152 128); 00153 00154 protected: 00155 00162 float64_t AA_helper(std::string &path, const char* joint_seq, 00163 unsigned int index); 00164 00174 float64_t compute_helper(const char* joint_seq, 00175 std::vector<unsigned int> joint_index, 00176 std::vector<unsigned int> joint_mismatch, std::string path, 00177 unsigned int d, const int & alen); 00178 00186 void compute_helper_all(const char* joint_seq, 00187 std::vector<struct joint_list_struct> & joint_list, 00188 std::string path, unsigned int d); 00189 00191 void compute_all(); 00192 00201 float64_t compute(int32_t idx_a, int32_t idx_b); 00202 00205 virtual void register_params(); 00208 void register_alphabet(); 00209 00210 protected: 00212 CAlphabet* alphabet; 00214 int32_t degree; 00216 int32_t max_mismatch; 00218 SGMatrix<float64_t> AA_matrix; 00220 float64_t width; 00221 00223 bool initialized; 00224 00226 CDynamicArray<float64_t>* kernel_matrix; // 2d 00228 int32_t kernel_matrix_length; 00230 int32_t target_letter_0; 00231 00232 private: 00233 void init(); 00234 }; 00235 00236 } 00237 00238 #endif /* _SPECTRUMMISMATCHRBFKERNEL_H__ */