33 using namespace shogun;
43 float64_t* AA_matrix_, int32_t nr, int32_t nc, int32_t degree_,
44 int32_t max_mismatch_,
float64_t width_) :
45 CStringKernel<char>(size), alphabet(NULL), degree(degree_), max_mismatch(
46 max_mismatch_), width(width_)
56 int32_t nr, int32_t nc, int32_t degree_, int32_t max_mismatch_,
58 CStringKernel<char>(size), alphabet(NULL), degree(degree_), max_mismatch(
59 max_mismatch_), width(width_)
76 int32_t lhs_changed=(
lhs!=l);
77 int32_t rhs_changed=(
rhs!=r);
81 SG_DEBUG(
"lhs_changed: %i\n", lhs_changed)
82 SG_DEBUG(
"rhs_changed: %i\n", rhs_changed)
112 const char* joint_seq,
unsigned int index)
116 for (
unsigned int i=0; i<path.size(); i++)
118 if (path[i]!=joint_seq[index+i])
127 return exp(-diff/
width);
131 std::vector<struct joint_list_struct> &joint_list, std::string path,
134 const char* AA=
"ACDEFGHIKLMNPQRSTVWY";
135 const unsigned int num_AA=strlen(AA);
137 assert(path.size()==d);
139 for (
unsigned int i=0; i<num_AA; i++)
141 std::vector<struct joint_list_struct> joint_list_;
157 for (
unsigned int j=0; j<joint_list.size(); j++)
159 if (joint_seq[joint_list[j].index+d]!=AA[i])
161 if (joint_list[j].mismatch+1<=(
unsigned int)
max_mismatch)
163 struct joint_list_struct list_item;
164 list_item=joint_list[j];
165 list_item.mismatch=joint_list[j].mismatch+1;
166 joint_list_.push_back(list_item);
170 joint_list_.push_back(joint_list[j]);
173 if (joint_list_.size()>0)
175 std::string path_=path+AA[i];
177 if (d+1<(
unsigned int)
degree)
187 for (
unsigned int j=0; j<joint_list_.size(); j++)
191 feats[joint_list_[j].ex_index]++;
197 if (joint_list_[j].mismatch!=0)
198 feats[joint_list_[j].ex_index]+=
AA_helper(path_,
199 joint_seq, joint_list_[j].index);
201 feats[joint_list_[j].ex_index]++;
205 std::vector<int> idx;
210 for (
unsigned int r=0; r<idx.size(); r++)
211 for (
unsigned int s=r; s<idx.size(); s++)
214 feats[idx[r]]*feats[idx[s]]
216 idx[s]), idx[r], idx[s]);
220 feats[idx[r]]*feats[idx[s]]
222 idx[s]), idx[r], idx[s]);
224 feats[idx[r]]*feats[idx[s]]
226 idx[r]), idx[s], idx[r]);
237 std::string joint_seq;
238 std::vector<struct joint_list_struct> joint_list;
254 for (
int apos=0; apos+
degree-1<alen; apos++)
256 struct joint_list_struct list_item;
257 list_item.ex_index=i;
258 list_item.index=apos+joint_seq.size();
259 list_item.mismatch=0;
261 joint_list.push_back(list_item);
263 joint_seq+=std::string(avec, alen);
277 int32_t nr, int32_t nc)
281 if (nr!=128 || nc!=128)
282 SG_ERROR(
"AA_matrix should be of shape 128x128\n")
314 "the kernel matrix with its length "
315 "defined by the number of vectors of the string features",
325 void CSpectrumMismatchRBFKernel::init()