|
SHOGUN v0.9.3
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 2008 Christian Igel, Tobias Glasmachers 00008 * Copyright (C) 2008 Christian Igel, Tobias Glasmachers 00009 * 00010 * Shogun adjustments (W) 2008-2009 Soeren Sonnenburg 00011 * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00012 */ 00013 #ifndef _OLIGOSTRINGKERNEL_H_ 00014 #define _OLIGOSTRINGKERNEL_H_ 00015 00016 #include "kernel/StringKernel.h" 00017 00018 #include <vector> 00019 #include <string> 00020 00021 namespace shogun 00022 { 00041 class COligoStringKernel : public CStringKernel<char> 00042 { 00043 public: 00049 COligoStringKernel(int32_t cache_size, int32_t k, float64_t width); 00050 00052 virtual ~COligoStringKernel(); 00053 00060 virtual bool init(CFeatures* l, CFeatures* r); 00061 00066 virtual EKernelType get_kernel_type() { return K_OLIGO; } 00067 00072 virtual const char* get_name() const { return "Oligo"; } 00073 00074 00075 virtual float64_t compute(int32_t x, int32_t y); 00076 00079 virtual void cleanup(); 00080 00081 protected: 00095 static void encodeOligo( 00096 const std::string& sequence, uint32_t k_mer_length, 00097 const std::string& allowed_characters, 00098 std::vector< std::pair<int32_t, float64_t> >& values); 00099 00107 static void getSequences( 00108 const std::vector<std::string>& sequences, 00109 uint32_t k_mer_length, const std::string& allowed_characters, 00110 std::vector< std::vector< std::pair<int32_t, float64_t> > >& encoded_sequences); 00111 00127 float64_t kernelOligoFast( 00128 const std::vector< std::pair<int32_t, float64_t> >& x, 00129 const std::vector< std::pair<int32_t, float64_t> >& y, 00130 int32_t max_distance = -1); 00131 00132 private: 00143 void getExpFunctionCache(uint32_t sequence_length); 00144 00145 static inline bool cmpOligos_(std::pair<int32_t, float64_t> a, 00146 std::pair<int32_t, float64_t> b ) 00147 { 00148 return (a.second < b.second); 00149 } 00150 00151 protected: 00153 int32_t k; 00155 float64_t width; 00157 float64_t* gauss_table; 00158 }; 00159 } 00160 #endif // _OLIGOSTRINGKERNEL_H_