CommWordStringKernel.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) 1999-2009 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #ifndef _COMMWORDSTRINGKERNEL_H___
00013 #define _COMMWORDSTRINGKERNEL_H___
00014 
00015 #include "lib/common.h"
00016 #include "lib/Mathematics.h"
00017 #include "kernel/StringKernel.h"
00018 
00019 namespace shogun
00020 {
00046 class CCommWordStringKernel : public CStringKernel<uint16_t>
00047 {
00048     friend class CVarianceKernelNormalizer;
00049     friend class CSqrtDiagKernelNormalizer;
00050     friend class CAvgDiagKernelNormalizer;
00051     friend class CRidgeKernelNormalizer;
00052     friend class CFirstElementKernelNormalizer;
00053     friend class CTanimotoKernelNormalizer;
00054     friend class CDiceKernelNormalizer;
00055 
00056     public:
00062         CCommWordStringKernel(int32_t size, bool use_sign);
00063 
00071         CCommWordStringKernel(
00072             CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r,
00073             bool use_sign=false, int32_t size=10);
00074 
00075         virtual ~CCommWordStringKernel();
00076 
00083         virtual bool init(CFeatures* l, CFeatures* r);
00084 
00086         virtual void cleanup();
00087 
00092         virtual EKernelType get_kernel_type() { return K_COMMWORDSTRING; }
00093 
00098         virtual const char* get_name() const { return "CommWordString"; }
00099 
00104         virtual bool init_dictionary(int32_t size);
00105 
00113         virtual bool init_optimization(
00114             int32_t count, int32_t *IDX, float64_t* weights);
00115 
00120         virtual bool delete_optimization();
00121 
00127         virtual float64_t compute_optimized(int32_t idx);
00128 
00134         virtual void add_to_normal(int32_t idx, float64_t weight);
00135 
00137         virtual void clear_normal();
00138 
00143         inline virtual EFeatureType get_feature_type() { return F_WORD; }
00144 
00150         void get_dictionary(int32_t& dsize, float64_t*& dweights)
00151         {
00152             dsize=dictionary_size;
00153             dweights = dictionary_weights;
00154         }
00155 
00168         virtual float64_t* compute_scoring(
00169             int32_t max_degree, int32_t& num_feat, int32_t& num_sym,
00170             float64_t* target, int32_t num_suppvec, int32_t* IDX,
00171             float64_t* alphas, bool do_init=true);
00172 
00181         char* compute_consensus(
00182             int32_t &num_feat, int32_t num_suppvec, int32_t* IDX,
00183             float64_t* alphas);
00184 
00189         void set_use_dict_diagonal_optimization(bool flag)
00190         {
00191             use_dict_diagonal_optimization=flag;
00192         }
00193 
00198         bool get_use_dict_diagonal_optimization()
00199         {
00200             return use_dict_diagonal_optimization;
00201         }
00202         
00203     protected:
00212         inline virtual float64_t compute(int32_t idx_a, int32_t idx_b)
00213         {
00214             return compute_helper(idx_a, idx_b, false);
00215         }
00216 
00224         virtual float64_t compute_helper(
00225             int32_t idx_a, int32_t idx_b, bool do_sort);
00226 
00232         virtual float64_t compute_diag(int32_t idx_a);
00233 
00234     protected:
00236         int32_t dictionary_size;
00239         float64_t* dictionary_weights;
00240 
00242         bool use_sign;
00243 
00245         bool use_dict_diagonal_optimization;
00247         int32_t* dict_diagonal_optimization;
00248 };
00249 }
00250 #endif /* _COMMWORDSTRINGKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation