Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
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/StringKernel.h>
00018 #include <shogun/features/StringFeatures.h>
00019
00020
00021 #include <shogun/lib/Array.h>
00022 #include <shogun/lib/Array2.h>
00023 #include <string>
00024
00025 namespace shogun
00026 {
00027
00028 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00029
00030 struct joint_list_struct
00031 {
00033 unsigned int ex_index;
00035 unsigned int index;
00037 unsigned int mismatch;
00038 };
00039 #endif
00040
00042 class CSpectrumMismatchRBFKernel: public CStringKernel<char>
00043 {
00044 public:
00046 CSpectrumMismatchRBFKernel();
00047
00058 CSpectrumMismatchRBFKernel(int32_t size, float64_t* AA_matrix_, int32_t nr_, int32_t nc_, int32_t degree, int32_t max_mismatch, float64_t width);
00059
00072 CSpectrumMismatchRBFKernel(
00073 CStringFeatures<char>* l, CStringFeatures<char>* r,
00074 int32_t size, float64_t* AA_matrix_, int32_t nr_,
00075 int32_t nc_, int32_t degree, int32_t max_mismatch, 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() { return K_SPECTRUMMISMATCHRBF; }
00096
00101 virtual const char* get_name() const { return "SpectrumMismatchRBFKernel"; }
00102
00108 bool set_max_mismatch(int32_t max);
00109
00114 inline int32_t get_max_mismatch() const { return max_mismatch; }
00115
00121 inline bool set_degree(int32_t deg) { degree=deg; return true; }
00122
00127 inline int32_t get_degree() const { return degree; }
00128
00135 bool set_AA_matrix(float64_t* AA_matrix_=NULL, int32_t nr=128, int32_t nc=128);
00136
00137 protected:
00138
00145 float64_t AA_helper(std::string &path, const char* joint_seq, unsigned int index);
00146
00156 float64_t compute_helper(const char* joint_seq,
00157 std::vector<unsigned int> joint_index, std::vector<unsigned int> joint_mismatch,
00158 std::string path, unsigned int d,
00159 const int & alen) ;
00160
00168 void compute_helper_all(const char* joint_seq,
00169 std::vector<struct joint_list_struct> & joint_list,
00170 std::string path, unsigned int d);
00171
00173 void compute_all();
00174
00183 float64_t compute(int32_t idx_a, int32_t idx_b);
00184
00186 virtual void remove_lhs();
00189 virtual void register_params();
00192 void register_alphabet();
00193
00194
00195 protected:
00197 CAlphabet* alphabet;
00199 int32_t degree;
00201 int32_t max_mismatch;
00203 float64_t* AA_matrix;
00205 int32_t AA_matrix_length;
00207 float64_t width;
00208
00210 bool initialized;
00211
00213 CArray2<float64_t> kernel_matrix ;
00215 int32_t kernel_matrix_length;
00217 int32_t target_letter_0;
00218
00219 private:
00220 void init();
00221 };
00222
00223 }
00224
00225 #endif