SHOGUN
v3.2.0
|
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 <shogun/lib/common.h> 00016 #include <shogun/mathematics/Math.h> 00017 #include <shogun/kernel/string/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: 00058 CCommWordStringKernel(); 00059 00065 CCommWordStringKernel(int32_t size, bool use_sign); 00066 00074 CCommWordStringKernel( 00075 CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r, 00076 bool use_sign=false, int32_t size=10); 00077 00078 virtual ~CCommWordStringKernel(); 00079 00086 virtual bool init(CFeatures* l, CFeatures* r); 00087 00089 virtual void cleanup(); 00090 00095 virtual EKernelType get_kernel_type() { return K_COMMWORDSTRING; } 00096 00101 virtual const char* get_name() const { return "CommWordStringKernel"; } 00102 00107 virtual bool init_dictionary(int32_t size); 00108 00116 virtual bool init_optimization( 00117 int32_t count, int32_t *IDX, float64_t* weights); 00118 00123 virtual bool delete_optimization(); 00124 00130 virtual float64_t compute_optimized(int32_t idx); 00131 00137 virtual void add_to_normal(int32_t idx, float64_t weight); 00138 00140 virtual void clear_normal(); 00141 00146 virtual EFeatureType get_feature_type() { return F_WORD; } 00147 00153 void get_dictionary(int32_t& dsize, float64_t*& dweights) 00154 { 00155 dsize=dictionary_size; 00156 dweights = dictionary_weights; 00157 } 00158 00171 virtual float64_t* compute_scoring( 00172 int32_t max_degree, int32_t& num_feat, int32_t& num_sym, 00173 float64_t* target, int32_t num_suppvec, int32_t* IDX, 00174 float64_t* alphas, bool do_init=true); 00175 00184 char* compute_consensus( 00185 int32_t &num_feat, int32_t num_suppvec, int32_t* IDX, 00186 float64_t* alphas); 00187 00192 void set_use_dict_diagonal_optimization(bool flag) 00193 { 00194 use_dict_diagonal_optimization=flag; 00195 } 00196 00201 bool get_use_dict_diagonal_optimization() 00202 { 00203 return use_dict_diagonal_optimization; 00204 } 00205 00206 protected: 00215 virtual float64_t compute(int32_t idx_a, int32_t idx_b) 00216 { 00217 return compute_helper(idx_a, idx_b, false); 00218 } 00219 00227 virtual float64_t compute_helper( 00228 int32_t idx_a, int32_t idx_b, bool do_sort); 00229 00235 virtual float64_t compute_diag(int32_t idx_a); 00236 00237 private: 00238 void init(); 00239 00240 protected: 00242 int32_t dictionary_size; 00245 float64_t* dictionary_weights; 00246 00248 bool use_sign; 00249 00251 bool use_dict_diagonal_optimization; 00253 int32_t* dict_diagonal_optimization; 00254 }; 00255 } 00256 #endif /* _COMMWORDSTRINGKERNEL_H__ */