SHOGUN  v3.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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/common.h>
18 
19 namespace shogun
20 {
21 template <class T> class CDynamicArray;
22 template <class ST> class CStringFeatures;
23 
48 class CCommUlongStringKernel: public CStringKernel<uint64_t>
49 {
50  public:
56  CCommUlongStringKernel(int32_t size=10, bool use_sign=false);
57 
67  bool use_sign=false,
68  int32_t size=10);
69 
70  virtual ~CCommUlongStringKernel();
71 
78  virtual bool init(CFeatures* l, CFeatures* r);
79 
81  virtual void cleanup();
82 
88 
93  virtual const char* get_name() const { return "CommUlongStringKernel"; }
94 
102  virtual bool init_optimization(
103  int32_t count, int32_t* IDX, float64_t* weights);
104 
109  virtual bool delete_optimization();
110 
116  virtual float64_t compute_optimized(int32_t idx);
117 
129  inline void merge_dictionaries(
130  int32_t& t, int32_t j, int32_t& k, uint64_t* vec, SGVector<uint64_t> dic,
131  SGVector<float64_t> dic_weights, float64_t weight, int32_t vec_idx)
132  {
133  while (k<dictionary.vlen && dictionary[k] < vec[j-1])
134  {
135  dic[t]=dictionary[k];
136  dic_weights[t]=dictionary_weights[k];
137  t++;
138  k++;
139  }
140 
141  if (k<dictionary.vlen && dictionary[k]==vec[j-1])
142  {
143  dic[t]=vec[j-1];
144  dic_weights[t]=dictionary_weights[k]+normalizer->normalize_lhs(weight, vec_idx);
145  k++;
146  }
147  else
148  {
149  dic[t]=vec[j-1];
150  dic_weights[t]=normalizer->normalize_lhs(weight, vec_idx);
151  }
152  t++;
153  }
154 
160  virtual void add_to_normal(int32_t idx, float64_t weight);
161 
163  virtual void clear_normal();
164 
166  virtual void remove_lhs();
167 
169  virtual void remove_rhs();
170 
175  virtual EFeatureType get_feature_type() { return F_ULONG; }
176 
184  int32_t &dsize, uint64_t*& dict, float64_t*& dweights)
185  {
186  dsize=dictionary.vlen;
187  dict=dictionary.vector;
188  dweights = dictionary_weights.vector;
189  }
190 
191  protected:
200  float64_t compute(int32_t idx_a, int32_t idx_b);
201 
202  protected:
207 
209  bool use_sign;
210 };
211 }
212 #endif /* _COMMULONGFSTRINGKERNEL_H__ */
virtual EFeatureType get_feature_type()
Template class StringFeatures implements a list of strings.
Definition: WDSVMOcas.h:23
EKernelType
Definition: Kernel.h:51
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:706
double float64_t
Definition: common.h:48
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:16
SGVector< float64_t > dictionary_weights
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
The class Features is the base class of all feature objects.
Definition: Features.h:62
CKernelNormalizer * normalizer
Definition: Kernel.h:731
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:24

SHOGUN Machine Learning Toolbox - Documentation