SparseSpatialSampleStringKernel.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) 2010 Soeren Sonnenburg
00008  * Copyright (C) 2010 Berlin Institute of Technology
00009  */
00010 
00011 #ifndef _SPARSESPATIALSAMPLESTRINGKERNEL_H___
00012 #define _SPARSESPATIALSAMPLESTRINGKERNEL_H___
00013 
00014 #include <shogun/lib/common.h>
00015 #include <shogun/kernel/StringKernel.h>
00016 
00017 namespace shogun
00018 {
00020     struct SSKFeatures
00021     {
00023         int *features;
00025         int *group;
00027         int n; 
00028     };
00029 
00034 class CSparseSpatialSampleStringKernel: public CStringKernel<char>
00035 {
00036     public:
00039         CSparseSpatialSampleStringKernel();
00040 
00046         CSparseSpatialSampleStringKernel(CStringFeatures<char>* l, CStringFeatures<char>* r);
00047 
00048         virtual ~CSparseSpatialSampleStringKernel();
00049 
00056         virtual bool init(CFeatures* l, CFeatures* r);
00057 
00059         virtual void cleanup();
00060 
00065         virtual EKernelType get_kernel_type()
00066         {
00067             return K_SPARSESPATIALSAMPLE;
00068         }
00069 
00073         void set_d(int32_t max_distance)
00074         {
00075             ASSERT(d>0);
00076             d=max_distance;
00077         }
00078 
00080         int32_t get_d()
00081         {
00082             return d;
00083         }
00084 
00088         void set_t(int32_t sequence_length)
00089         {
00090             ASSERT(t==2 || t==3);
00091             t=sequence_length;
00092         }
00093 
00095         int32_t get_t()
00096         {
00097             return t;
00098         }
00099 
00104         virtual const char* get_name() const { return "SparseSpatialSampleStringKernel"; }
00105 
00106     protected:
00115         virtual float64_t compute(int32_t idx_a, int32_t idx_b);
00116 
00124         SSKFeatures *extractTriple(int **S, int *len, int nStr, int d1, int d2);
00131         SSKFeatures *extractDouble(int **S, int *len, int nStr, int d1);
00136         void compute_double(int32_t idx_a, int32_t idx_b);
00141         void compute_triple(int32_t idx_a, int32_t idx_b);
00148         int* cntsrtna(int *sx, int k, int r, int na);
00157         void countAndUpdate(int *outK, int *sx, int *g, int k, int r, int nStr);
00158 
00159     protected:
00162         int32_t t;
00163 
00166         int32_t d;
00167 
00169         bool isVerbose;
00170 };
00171 }
00172 #endif /* _SPARSESPATIALSAMPLESTRINGKERNEL_H___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation