SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OligoStringKernel.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) 2008 Christian Igel, Tobias Glasmachers
8  * Copyright (C) 2008 Christian Igel, Tobias Glasmachers
9  *
10  * Shogun adjustments (W) 2008-2009 Soeren Sonnenburg
11  * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max-Planck-Society
12  */
13 #ifndef _OLIGOSTRINGKERNEL_H_
14 #define _OLIGOSTRINGKERNEL_H_
15 
17 
18 #include <vector>
19 #include <string>
20 
21 namespace shogun
22 {
41 class COligoStringKernel : public CStringKernel<char>
42 {
43  public:
46 
52  COligoStringKernel(int32_t cache_size, int32_t k, float64_t width);
53 
55  virtual ~COligoStringKernel();
56 
63  virtual bool init(CFeatures* l, CFeatures* r);
64 
69  virtual EKernelType get_kernel_type() { return K_OLIGO; }
70 
75  virtual const char* get_name() const { return "OligoStringKernel"; }
76 
77 
78  virtual float64_t compute(int32_t x, int32_t y);
79 
82  virtual void cleanup();
83 
84  protected:
98  static void encodeOligo(
99  const std::string& sequence, uint32_t k_mer_length,
100  const std::string& allowed_characters,
101  std::vector< std::pair<int32_t, float64_t> >& values);
102 
110  static void getSequences(
111  const std::vector<std::string>& sequences,
112  uint32_t k_mer_length, const std::string& allowed_characters,
113  std::vector< std::vector< std::pair<int32_t, float64_t> > >& encoded_sequences);
114 
131  const std::vector< std::pair<int32_t, float64_t> >& x,
132  const std::vector< std::pair<int32_t, float64_t> >& y,
133  int32_t max_distance = -1);
134 
135  private:
146  void getExpFunctionCache(uint32_t sequence_length);
147 
148  static inline bool cmpOligos_(std::pair<int32_t, float64_t> a,
149  std::pair<int32_t, float64_t> b )
150  {
151  return (a.second < b.second);
152  }
153 
154  void init();
155 
156  protected:
158  int32_t k;
165 };
166 }
167 #endif // _OLIGOSTRINGKERNEL_H_

SHOGUN Machine Learning Toolbox - Documentation