SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommUlongStringKernel.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef _COMMULONGSTRINGKERNEL_H___
12 #define _COMMULONGSTRINGKERNEL_H___
13 
14 #include <shogun/lib/config.h>
15 
16 #include <shogun/lib/common.h>
20 
21 namespace shogun
22 {
23 template <class T> class CDynamicArray;
24 template <class ST> class CStringFeatures;
25 
50 class CCommUlongStringKernel: public CStringKernel<uint64_t>
51 {
52  public:
58  CCommUlongStringKernel(int32_t size=10, bool use_sign=false);
59 
69  bool use_sign=false,
70  int32_t size=10);
71 
72  virtual ~CCommUlongStringKernel();
73 
80  virtual bool init(CFeatures* l, CFeatures* r);
81 
83  virtual void cleanup();
84 
90 
95  virtual const char* get_name() const { return "CommUlongStringKernel"; }
96 
104  virtual bool init_optimization(
105  int32_t count, int32_t* IDX, float64_t* weights);
106 
111  virtual bool delete_optimization();
112 
118  virtual float64_t compute_optimized(int32_t idx);
119 
131  inline void merge_dictionaries(
132  int32_t& t, int32_t j, int32_t& k, uint64_t* vec, SGVector<uint64_t> dic,
133  SGVector<float64_t> dic_weights, float64_t weight, int32_t vec_idx)
134  {
135  while (k<dictionary.vlen && dictionary[k] < vec[j-1])
136  {
137  dic[t]=dictionary[k];
138  dic_weights[t]=dictionary_weights[k];
139  t++;
140  k++;
141  }
142 
143  if (k<dictionary.vlen && dictionary[k]==vec[j-1])
144  {
145  dic[t]=vec[j-1];
146  dic_weights[t]=dictionary_weights[k]+normalizer->normalize_lhs(weight, vec_idx);
147  k++;
148  }
149  else
150  {
151  dic[t]=vec[j-1];
152  dic_weights[t]=normalizer->normalize_lhs(weight, vec_idx);
153  }
154  t++;
155  }
156 
162  virtual void add_to_normal(int32_t idx, float64_t weight);
163 
165  virtual void clear_normal();
166 
168  virtual void remove_lhs();
169 
171  virtual void remove_rhs();
172 
177  virtual EFeatureType get_feature_type() { return F_ULONG; }
178 
186  int32_t &dsize, uint64_t*& dict, float64_t*& dweights)
187  {
188  dsize=dictionary.vlen;
189  dict=dictionary.vector;
190  dweights = dictionary_weights.vector;
191  }
192 
193  protected:
202  float64_t compute(int32_t idx_a, int32_t idx_b);
203 
204  protected:
209 
211  bool use_sign;
212 };
213 }
214 #endif /* _COMMULONGFSTRINGKERNEL_H__ */
virtual EFeatureType get_feature_type()
Template class StringFeatures implements a list of strings.
EKernelType
Definition: Kernel.h:57
The CommUlongString kernel may be used to compute the spectrum kernel from strings that have been map...
void get_dictionary(int32_t &dsize, uint64_t *&dict, float64_t *&dweights)
virtual const char * get_name() const
virtual float64_t compute_optimized(int32_t idx)
virtual bool init(CFeatures *l, CFeatures *r)
CCommUlongStringKernel(int32_t size=10, bool use_sign=false)
float64_t compute(int32_t idx_a, int32_t idx_b)
index_t vlen
Definition: SGVector.h:492
double float64_t
Definition: common.h:50
virtual void add_to_normal(int32_t idx, float64_t weight)
virtual EKernelType get_kernel_type()
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
EFeatureType
shogun feature type
Definition: FeatureTypes.h:19
SGVector< float64_t > dictionary_weights
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
The class Features is the base class of all feature objects.
Definition: Features.h:68
CKernelNormalizer * normalizer
Definition: Kernel.h:1087
void merge_dictionaries(int32_t &t, int32_t j, int32_t &k, uint64_t *vec, SGVector< uint64_t > dic, SGVector< float64_t > dic_weights, float64_t weight, int32_t vec_idx)
virtual float64_t normalize_lhs(float64_t value, int32_t idx_lhs)=0
Template class StringKernel, is the base class of all String Kernels.
Definition: StringKernel.h:26

SHOGUN Machine Learning Toolbox - Documentation