|
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-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 "lib/common.h" 00016 #include "lib/Trie.h" 00017 #include "kernel/StringKernel.h" 00018 #include "features/StringFeatures.h" 00019 00020 00021 #include "lib/Array.h" 00022 #include "lib/Array2.h" 00023 00024 namespace shogun 00025 { 00026 00027 struct joint_list_struct 00028 { 00029 unsigned int ex_index ; 00030 unsigned int index ; 00031 unsigned int mismatch ; 00032 } ; 00033 00034 class CSpectrumMismatchRBFKernel: public CStringKernel<char> 00035 { 00036 public: 00037 00043 CSpectrumMismatchRBFKernel(int32_t size, float64_t* AA_matrix, int32_t degree, int32_t max_mismatch, float64_t width); 00044 00051 CSpectrumMismatchRBFKernel( 00052 CStringFeatures<char>* l, CStringFeatures<char>* r, int32_t size, float64_t* AA_matrix, int32_t degree, int32_t max_mismatch, float64_t width); 00053 00054 virtual ~CSpectrumMismatchRBFKernel(); 00055 00062 virtual bool init(CFeatures* l, CFeatures* r); 00063 00065 virtual void cleanup(); 00066 00071 int32_t get_degree() const 00072 { 00073 return degree; 00074 } 00075 00080 int32_t get_max_mismatch() const 00081 { 00082 return max_mismatch; 00083 } 00084 00089 virtual EKernelType get_kernel_type() { return K_SPECTRUMMISMATCHRBF; } 00090 00095 virtual const char* get_name() const { return "SpectrumMismatchRBF"; } 00096 00102 bool set_max_mismatch(int32_t max); 00103 00108 inline int32_t get_max_mismatch() { return max_mismatch; } 00109 00115 inline bool set_degree(int32_t deg) { degree=deg; return true; } 00116 00121 inline int32_t get_degree() { return degree; } 00122 00123 00124 bool set_AA_matrix(float64_t* AA_matrix_); 00125 00126 protected: 00127 00128 float64_t AA_helper(std::string &path, const char* joint_seq, unsigned int index) ; 00129 float64_t compute_helper(const char* joint_seq, 00130 std::vector<unsigned int> joint_index, std::vector<unsigned int> joint_mismatch, 00131 std::string path, unsigned int d, 00132 const int & alen) ; 00133 00134 00135 void compute_helper_all(const char* joint_seq, 00136 std::vector<struct joint_list_struct> & joint_list, 00137 std::string path, unsigned int d) ; 00138 void compute_all() ; 00139 00140 00149 float64_t compute(int32_t idx_a, int32_t idx_b); 00150 00152 virtual void remove_lhs(); 00153 00154 00155 protected: 00157 CAlphabet* alphabet; 00159 int32_t degree; 00161 int32_t max_mismatch; 00163 double* AA_matrix ; 00165 double width; 00166 00168 bool initialized; 00169 00170 00171 CArray2<float64_t> kernel_matrix ; 00172 int target_letter_0 ; 00173 }; 00174 00175 } 00176 00177 00178 00179 #endif /* _SPECTRUMMISMATCHRBFKERNEL_H__ */