CommUlongStringKernel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _COMMULONGSTRINGKERNEL_H___
00013 #define _COMMULONGSTRINGKERNEL_H___
00014
00015 #include "lib/common.h"
00016 #include "lib/Mathematics.h"
00017 #include "lib/DynamicArray.h"
00018 #include "kernel/StringKernel.h"
00019
00043 class CCommUlongStringKernel: public CStringKernel<uint64_t>
00044 {
00045 public:
00051 CCommUlongStringKernel(int32_t size=10, bool use_sign=false);
00052
00060 CCommUlongStringKernel(
00061 CStringFeatures<uint64_t>* l, CStringFeatures<uint64_t>* r,
00062 bool use_sign=false,
00063 int32_t size=10);
00064
00065 virtual ~CCommUlongStringKernel();
00066
00073 virtual bool init(CFeatures* l, CFeatures* r);
00074
00076 virtual void cleanup();
00077
00083 bool load_init(FILE* src);
00084
00090 bool save_init(FILE* dest);
00091
00096 virtual EKernelType get_kernel_type() { return K_COMMULONGSTRING; }
00097
00102 virtual const char* get_name() { return "CommUlongString"; }
00103
00111 virtual bool init_optimization(
00112 int32_t count, int32_t* IDX, float64_t* weights);
00113
00118 virtual bool delete_optimization();
00119
00125 virtual float64_t compute_optimized(int32_t idx);
00126
00138 inline void merge_dictionaries(
00139 int32_t& t, int32_t j, int32_t& k, uint64_t* vec, uint64_t* dic,
00140 float64_t* dic_weights, float64_t weight, int32_t vec_idx)
00141 {
00142 while (k<dictionary.get_num_elements() && dictionary[k] < vec[j-1])
00143 {
00144 dic[t]=dictionary[k];
00145 dic_weights[t]=dictionary_weights[k];
00146 t++;
00147 k++;
00148 }
00149
00150 if (k<dictionary.get_num_elements() && dictionary[k]==vec[j-1])
00151 {
00152 dic[t]=vec[j-1];
00153 dic_weights[t]=dictionary_weights[k]+normalizer->normalize_lhs(weight, vec_idx);
00154 k++;
00155 }
00156 else
00157 {
00158 dic[t]=vec[j-1];
00159 dic_weights[t]=normalizer->normalize_lhs(weight, vec_idx);
00160 }
00161 t++;
00162 }
00163
00169 virtual void add_to_normal(int32_t idx, float64_t weight);
00170
00172 virtual void clear_normal();
00173
00175 virtual void remove_lhs();
00176
00178 virtual void remove_rhs();
00179
00184 inline virtual EFeatureType get_feature_type() { return F_ULONG; }
00185
00192 void get_dictionary(
00193 int32_t &dsize, uint64_t*& dict, float64_t*& dweights)
00194 {
00195 dsize=dictionary.get_num_elements();
00196 dict=dictionary.get_array();
00197 dweights = dictionary_weights.get_array();
00198 }
00199
00200 protected:
00209 float64_t compute(int32_t idx_a, int32_t idx_b);
00210
00211 protected:
00213 CDynamicArray<uint64_t> dictionary;
00215 CDynamicArray<float64_t> dictionary_weights;
00216
00218 bool use_sign;
00219 };
00220
00221 #endif