SHOGUN  v3.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,2013 Soeren Sonnenburg
11  * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max-Planck-Society
12  * Copyright (C) 2013 Soeren Sonnenburg
13  */
14 #ifndef _OLIGOSTRINGKERNEL_H_
15 #define _OLIGOSTRINGKERNEL_H_
16 
18 
19 #include <vector>
20 #include <string>
21 
22 namespace shogun
23 {
42 class COligoStringKernel : public CStringKernel<char>
43 {
44  public:
47 
53  COligoStringKernel(int32_t cache_size, int32_t k, float64_t width);
54 
63  int32_t k, float64_t width);
64 
66  virtual ~COligoStringKernel();
67 
74  virtual bool init(CFeatures* l, CFeatures* r);
75 
80  virtual EKernelType get_kernel_type() { return K_OLIGO; }
81 
86  virtual const char* get_name() const { return "OligoStringKernel"; }
87 
88 
89  virtual float64_t compute(int32_t x, int32_t y);
90 
93  virtual void cleanup();
94 
95  protected:
109  static void encodeOligo(
110  const std::string& sequence, uint32_t k_mer_length,
111  const std::string& allowed_characters,
112  std::vector< std::pair<int32_t, float64_t> >& values);
113 
121  static void getSequences(
122  const std::vector<std::string>& sequences,
123  uint32_t k_mer_length, const std::string& allowed_characters,
124  std::vector< std::vector< std::pair<int32_t, float64_t> > >& encoded_sequences);
125 
142  const std::vector< std::pair<int32_t, float64_t> >& x,
143  const std::vector< std::pair<int32_t, float64_t> >& y,
144  int32_t max_distance = -1);
145 
154  const std::vector< std::pair<int32_t, float64_t> >& x,
155  const std::vector< std::pair<int32_t, float64_t> >& y);
156 
157 
158  private:
169  void getExpFunctionCache(uint32_t sequence_length);
170 
171  static inline bool cmpOligos_(std::pair<int32_t, float64_t> a,
172  std::pair<int32_t, float64_t> b )
173  {
174  return (a.second < b.second);
175  }
176 
177  void init();
178 
179  protected:
181  int32_t k;
186 };
187 }
188 #endif // _OLIGOSTRINGKERNEL_H_

SHOGUN Machine Learning Toolbox - Documentation