SHOGUN  v3.2.0
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  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  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__ */
virtual float64_t compute_optimized(int32_t idx)
void set_use_dict_diagonal_optimization(bool flag)
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
EKernelType
Definition: Kernel.h:51
virtual bool init_dictionary(int32_t size)
DiceKernelNormalizer performs kernel normalization inspired by the Dice coefficient (see http://en...
virtual float64_t compute(int32_t idx_a, int32_t idx_b)
virtual EFeatureType get_feature_type()
TanimotoKernelNormalizer performs kernel normalization inspired by the Tanimoto coefficient (see http...
virtual float64_t compute_helper(int32_t idx_a, int32_t idx_b, bool do_sort)
virtual float64_t compute_diag(int32_t idx_a)
The CommWordString kernel may be used to compute the spectrum kernel from strings that have been mapp...
double float64_t
Definition: common.h:48
Normalize the kernel by a constant obtained from the first element of the kernel matrix, i.e. .
Normalize the kernel by adding a constant term to its diagonal. This aids kernels to become positive ...
virtual EKernelType get_kernel_type()
virtual bool init(CFeatures *l, CFeatures *r)
virtual const char * get_name() const
EFeatureType
shogun feature type
Definition: FeatureTypes.h:16
void get_dictionary(int32_t &dsize, float64_t *&dweights)
SqrtDiagKernelNormalizer divides by the Square Root of the product of the diagonal elements...
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:16
virtual float64_t * compute_scoring(int32_t max_degree, int32_t &num_feat, int32_t &num_sym, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *alphas, bool do_init=true)
Normalize the kernel by either a constant or the average value of the diagonal elements (depending on...
The class Features is the base class of all feature objects.
Definition: Features.h:62
char * compute_consensus(int32_t &num_feat, int32_t num_suppvec, int32_t *IDX, float64_t *alphas)
virtual void add_to_normal(int32_t idx, float64_t weight)
Template class StringKernel, is the base class of all String Kernels.
Definition: StringKernel.h:24
VarianceKernelNormalizer divides by the ``variance''.

SHOGUN Machine Learning Toolbox - Documentation