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 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00009 */ 00010 00011 #ifndef _COMMULONGSTRINGKERNEL_H___ 00012 #define _COMMULONGSTRINGKERNEL_H___ 00013 00014 #include <shogun/lib/common.h> 00015 #include <shogun/mathematics/Math.h> 00016 #include <shogun/lib/DynamicArray.h> 00017 #include <shogun/kernel/string/StringKernel.h> 00018 00019 namespace shogun 00020 { 00021 template <class T> class CDynamicArray; 00022 template <class ST> class CStringFeatures; 00023 00048 class CCommUlongStringKernel: public CStringKernel<uint64_t> 00049 { 00050 public: 00056 CCommUlongStringKernel(int32_t size=10, bool use_sign=false); 00057 00065 CCommUlongStringKernel( 00066 CStringFeatures<uint64_t>* l, CStringFeatures<uint64_t>* r, 00067 bool use_sign=false, 00068 int32_t size=10); 00069 00070 virtual ~CCommUlongStringKernel(); 00071 00078 virtual bool init(CFeatures* l, CFeatures* r); 00079 00081 virtual void cleanup(); 00082 00087 virtual EKernelType get_kernel_type() { return K_COMMULONGSTRING; } 00088 00093 virtual const char* get_name() const { return "CommUlongStringKernel"; } 00094 00102 virtual bool init_optimization( 00103 int32_t count, int32_t* IDX, float64_t* weights); 00104 00109 virtual bool delete_optimization(); 00110 00116 virtual float64_t compute_optimized(int32_t idx); 00117 00129 inline void merge_dictionaries( 00130 int32_t& t, int32_t j, int32_t& k, uint64_t* vec, SGVector<uint64_t> dic, 00131 SGVector<float64_t> dic_weights, float64_t weight, int32_t vec_idx) 00132 { 00133 while (k<dictionary.vlen && dictionary[k] < vec[j-1]) 00134 { 00135 dic[t]=dictionary[k]; 00136 dic_weights[t]=dictionary_weights[k]; 00137 t++; 00138 k++; 00139 } 00140 00141 if (k<dictionary.vlen && dictionary[k]==vec[j-1]) 00142 { 00143 dic[t]=vec[j-1]; 00144 dic_weights[t]=dictionary_weights[k]+normalizer->normalize_lhs(weight, vec_idx); 00145 k++; 00146 } 00147 else 00148 { 00149 dic[t]=vec[j-1]; 00150 dic_weights[t]=normalizer->normalize_lhs(weight, vec_idx); 00151 } 00152 t++; 00153 } 00154 00160 virtual void add_to_normal(int32_t idx, float64_t weight); 00161 00163 virtual void clear_normal(); 00164 00166 virtual void remove_lhs(); 00167 00169 virtual void remove_rhs(); 00170 00175 virtual EFeatureType get_feature_type() { return F_ULONG; } 00176 00183 void get_dictionary( 00184 int32_t &dsize, uint64_t*& dict, float64_t*& dweights) 00185 { 00186 dsize=dictionary.vlen; 00187 dict=dictionary.vector; 00188 dweights = dictionary_weights.vector; 00189 } 00190 00191 protected: 00200 float64_t compute(int32_t idx_a, int32_t idx_b); 00201 00202 protected: 00204 SGVector<uint64_t> dictionary; 00206 SGVector<float64_t> dictionary_weights; 00207 00209 bool use_sign; 00210 }; 00211 } 00212 #endif /* _COMMULONGFSTRINGKERNEL_H__ */