OligoStringKernel.h

Go to the documentation of this file.
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 
00039 class COligoStringKernel : public CStringKernel<char>
00040 {
00041     public:
00047         COligoStringKernel(int32_t cache_size, int32_t k, float64_t width);
00048 
00050         virtual ~COligoStringKernel();
00051 
00058         virtual bool init(CFeatures* l, CFeatures* r);
00059 
00064         virtual bool load_init(FILE*)
00065         {
00066             return false;
00067         }
00068 
00073         virtual bool save_init(FILE*)
00074         {
00075             return false;
00076         }
00077 
00082         virtual EKernelType get_kernel_type() { return K_OLIGO; }
00083 
00088         virtual const char* get_name() const { return "Oligo"; }
00089 
00090 
00091         virtual float64_t compute(int32_t x, int32_t y);
00092 
00095         virtual void cleanup();
00096 
00097     protected:
00111         static void encodeOligo(
00112             const std::string& sequence, uint32_t k_mer_length,
00113             const std::string& allowed_characters,
00114             std::vector< std::pair<int32_t, float64_t> >&   values);
00115 
00123         static void getSequences(
00124             const std::vector<std::string>& sequences,
00125             uint32_t k_mer_length, const std::string& allowed_characters,
00126             std::vector< std::vector< std::pair<int32_t, float64_t> > >& encoded_sequences);
00127 
00143         float64_t kernelOligoFast(
00144             const std::vector< std::pair<int32_t, float64_t> >& x,
00145             const std::vector< std::pair<int32_t, float64_t> >& y,
00146             int32_t max_distance = -1);
00147 
00148     private: 
00159         void getExpFunctionCache(uint32_t sequence_length);
00160 
00161         static inline bool cmpOligos_(std::pair<int32_t, float64_t> a,
00162                 std::pair<int32_t, float64_t> b )
00163         {
00164             return (a.second < b.second);
00165         }
00166 
00167     protected:
00169         int32_t k;
00171         float64_t width;
00173         float64_t* gauss_table;
00174 };
00175 #endif // _OLIGOSTRINGKERNEL_H_

SHOGUN Machine Learning Toolbox - Documentation