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 "lib/common.h"
00015 #include "kernel/StringKernel.h"
00016 
00017 namespace shogun
00018 {
00019     struct SSKFeatures
00020     {
00021         int *features;
00022         int *group;
00023         int n; 
00024     };
00025 
00030 class CSparseSpatialSampleStringKernel: public CStringKernel<char>
00031 {
00032     public:
00035         CSparseSpatialSampleStringKernel();
00036 
00042         CSparseSpatialSampleStringKernel(CStringFeatures<char>* l, CStringFeatures<char>* r);
00043 
00044         virtual ~CSparseSpatialSampleStringKernel();
00045 
00052         virtual bool init(CFeatures* l, CFeatures* r);
00053 
00055         virtual void cleanup();
00056 
00061         virtual EKernelType get_kernel_type()
00062         {
00063             return K_SPARSESPATIALSAMPLE;
00064         }
00065 
00066         void set_d(int32_t max_distance)
00067         {
00068             ASSERT(d>0);
00069             d=max_distance;
00070         }
00071 
00072         int32_t get_d()
00073         {
00074             return d;
00075         }
00076 
00077         void set_t(int32_t sequence_length)
00078         {
00079             ASSERT(t==2 || t==3);
00080             t=sequence_length;
00081         }
00082 
00083         int32_t get_t()
00084         {
00085             return t;
00086         }
00087 
00092         virtual const char* get_name() const { return "SparseSpatialSampleStringKernel"; }
00093 
00094     protected:
00103         virtual float64_t compute(int32_t idx_a, int32_t idx_b);
00104 
00105         SSKFeatures *extractTriple(int **S, int *len, int nStr, int d1, int d2);
00106         SSKFeatures *extractDouble(int **S, int *len, int nStr, int d1);
00107         void compute_double(int32_t idx_a, int32_t idx_b);
00108         void compute_triple(int32_t idx_a, int32_t idx_b);
00109         int* cntsrtna(int *sx, int k, int r, int na);
00110         void countAndUpdate(int *outK, int *sx, int *g, int k, int r, int nStr);
00111 
00112     protected:
00115         int32_t t;
00116 
00119         int32_t d;
00120         bool isVerbose;
00121 };
00122 }
00123 #endif /* _SPARSESPATIALSAMPLESTRINGKERNEL_H___ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation