SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CommWordStringKernel.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  * Written (W) 1999-2008 Gunnar Raetsch
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
12 #ifndef _COMMWORDSTRINGKERNEL_H___
13 #define _COMMWORDSTRINGKERNEL_H___
14 
15 #include <shogun/lib/common.h>
18 
19 namespace shogun
20 {
46 class CCommWordStringKernel : public CStringKernel<uint16_t>
47 {
51  friend class CRidgeKernelNormalizer;
54  friend class CDiceKernelNormalizer;
55 
56  public:
59 
65  CCommWordStringKernel(int32_t size, bool use_sign);
66 
76  bool use_sign=false, int32_t size=10);
77 
78  virtual ~CCommWordStringKernel();
79 
86  virtual bool init(CFeatures* l, CFeatures* r);
87 
89  virtual void cleanup();
90 
96 
101  virtual const char* get_name() const { return "CommWordStringKernel"; }
102 
107  virtual bool init_dictionary(int32_t size);
108 
116  virtual bool init_optimization(
117  int32_t count, int32_t *IDX, float64_t* weights);
118 
123  virtual bool delete_optimization();
124 
130  virtual float64_t compute_optimized(int32_t idx);
131 
137  virtual void add_to_normal(int32_t idx, float64_t weight);
138 
140  virtual void clear_normal();
141 
146  inline virtual EFeatureType get_feature_type() { return F_WORD; }
147 
153  void get_dictionary(int32_t& dsize, float64_t*& dweights)
154  {
155  dsize=dictionary_size;
156  dweights = dictionary_weights;
157  }
158 
171  virtual float64_t* compute_scoring(
172  int32_t max_degree, int32_t& num_feat, int32_t& num_sym,
173  float64_t* target, int32_t num_suppvec, int32_t* IDX,
174  float64_t* alphas, bool do_init=true);
175 
184  char* compute_consensus(
185  int32_t &num_feat, int32_t num_suppvec, int32_t* IDX,
186  float64_t* alphas);
187 
193  {
195  }
196 
202  {
204  }
205 
206  protected:
215  inline virtual float64_t compute(int32_t idx_a, int32_t idx_b)
216  {
217  return compute_helper(idx_a, idx_b, false);
218  }
219 
227  virtual float64_t compute_helper(
228  int32_t idx_a, int32_t idx_b, bool do_sort);
229 
235  virtual float64_t compute_diag(int32_t idx_a);
236 
237  private:
238  void init();
239 
240  protected:
246 
248  bool use_sign;
249 
254 };
255 }
256 #endif /* _COMMWORDSTRINGKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation