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 "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 #include <string>
00024
00025 namespace shogun
00026 {
00027
00028 struct joint_list_struct
00029 {
00030 unsigned int ex_index ;
00031 unsigned int index ;
00032 unsigned int mismatch ;
00033 } ;
00034
00035 class CSpectrumMismatchRBFKernel: public CStringKernel<char>
00036 {
00037 public:
00039 CSpectrumMismatchRBFKernel(void);
00040
00046 CSpectrumMismatchRBFKernel(int32_t size, float64_t* AA_matrix_, int32_t nr_, int32_t nc_, int32_t degree, int32_t max_mismatch, float64_t width);
00047
00054 CSpectrumMismatchRBFKernel(
00055 CStringFeatures<char>* l, CStringFeatures<char>* r, int32_t size, float64_t* AA_matrix_, int32_t nr_, int32_t nc_, int32_t degree, int32_t max_mismatch, float64_t width);
00056
00057 virtual ~CSpectrumMismatchRBFKernel();
00058
00065 virtual bool init(CFeatures* l, CFeatures* r);
00066
00068 virtual void cleanup();
00069
00074 int32_t get_degree() const
00075 {
00076 return degree;
00077 }
00078
00083 int32_t get_max_mismatch() const
00084 {
00085 return max_mismatch;
00086 }
00087
00092 virtual EKernelType get_kernel_type() { return K_SPECTRUMMISMATCHRBF; }
00093
00098 virtual const char* get_name() const { return "SpectrumMismatchRBF"; }
00099
00105 bool set_max_mismatch(int32_t max);
00106
00111 inline int32_t get_max_mismatch() { return max_mismatch; }
00112
00118 inline bool set_degree(int32_t deg) { degree=deg; return true; }
00119
00124 inline int32_t get_degree() { return degree; }
00125
00126
00127 bool set_AA_matrix(float64_t* AA_matrix_=NULL, int32_t nr=128, int32_t nc=128);
00128
00129 protected:
00130
00131 float64_t AA_helper(std::string &path, const char* joint_seq, unsigned int index) ;
00132 float64_t compute_helper(const char* joint_seq,
00133 std::vector<unsigned int> joint_index, std::vector<unsigned int> joint_mismatch,
00134 std::string path, unsigned int d,
00135 const int & alen) ;
00136
00137
00138 void compute_helper_all(const char* joint_seq,
00139 std::vector<struct joint_list_struct> & joint_list,
00140 std::string path, unsigned int d) ;
00141 void compute_all() ;
00142
00143
00152 float64_t compute(int32_t idx_a, int32_t idx_b);
00153
00155 virtual void remove_lhs();
00156
00157
00158 protected:
00160 CAlphabet* alphabet;
00162 int32_t degree;
00164 int32_t max_mismatch;
00166 float64_t* AA_matrix;
00168 float64_t width;
00169
00171 bool initialized;
00172
00173
00174 CArray2<float64_t> kernel_matrix ;
00175 int32_t target_letter_0 ;
00176 };
00177
00178 }
00179
00180 #endif