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()
float64_t AA_helper(std::string &path, const char *joint_seq, unsigned int index)
bool set_max_mismatch(int32_t max)
void compute_helper_all(const char *joint_seq, std::vector< struct joint_list_struct > &joint_list, std::string path, unsigned int d)
virtual void register_params()
void set_const(const T &const_element)
EAlphabet get_alphabet() const
virtual int32_t get_num_vectors() const =0
The class Alphabet implements an alphabet and alphabet utility functions.
CDynamicArray< float64_t > * kernel_matrix
virtual ~CSpectrumMismatchRBFKernel()
virtual bool init(CFeatures *l, CFeatures *r)
Class SGObject is the base class of all shogun objects.
bool set_element(T e, int32_t idx1, int32_t idx2=0, int32_t idx3=0)
bool set_AA_matrix(float64_t *AA_matrix_=NULL, int32_t nr=128, int32_t nc=128)
CAlphabet * get_alphabet()
float64_t compute(int32_t idx_a, int32_t idx_b)
SGMatrix< float64_t > AA_matrix
bool resize_array(int32_t ndim1, int32_t ndim2=1, int32_t ndim3=1)
virtual bool init_normalizer()
CFeatures * rhs
feature vectors to occur on right hand side
all of classes and functions are contained in the shogun namespace
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
CSpectrumMismatchRBFKernel()
const T & element(int32_t idx1, int32_t idx2=0, int32_t idx3=0) const
int32_t kernel_matrix_length
Matrix::Scalar max(Matrix m)
Template class StringKernel, is the base class of all String Kernels.
const T & get_element(int32_t idx1, int32_t idx2=0, int32_t idx3=0) const