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-2008 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2008 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 
00043 class CCommWordStringKernel : public CStringKernel<uint16_t>
00044 {
00045     friend class CSqrtDiagKernelNormalizer;
00046 
00047     public:
00053         CCommWordStringKernel(int32_t size, bool use_sign);
00054 
00062         CCommWordStringKernel(
00063             CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r,
00064             bool use_sign=false, int32_t size=10);
00065 
00066         virtual ~CCommWordStringKernel();
00067 
00074         virtual bool init(CFeatures* l, CFeatures* r);
00075 
00077         virtual void cleanup();
00078 
00084         bool load_init(FILE* src);
00085 
00091         bool save_init(FILE* dest);
00092 
00097         virtual EKernelType get_kernel_type() { return K_COMMWORDSTRING; }
00098 
00103         virtual const char* get_name() { return "CommWordString"; }
00104 
00109         virtual bool init_dictionary(int32_t size);
00110 
00118         virtual bool init_optimization(
00119             int32_t count, int32_t *IDX, float64_t* weights);
00120 
00125         virtual bool delete_optimization();
00126 
00132         virtual float64_t compute_optimized(int32_t idx);
00133 
00139         virtual void add_to_normal(int32_t idx, float64_t weight);
00140 
00142         virtual void clear_normal();
00143 
00145         virtual void remove_lhs();
00146 
00148         virtual void remove_rhs();
00149 
00154         inline virtual EFeatureType get_feature_type() { return F_WORD; }
00155 
00161         void get_dictionary(int32_t& dsize, float64_t*& dweights)
00162         {
00163             dsize=dictionary_size;
00164             dweights = dictionary_weights;
00165         }
00166 
00179         virtual float64_t* compute_scoring(
00180             int32_t max_degree, int32_t& num_feat, int32_t& num_sym,
00181             float64_t* target, int32_t num_suppvec, int32_t* IDX,
00182             float64_t* alphas, bool do_init=true);
00183 
00192         char* compute_consensus(
00193             int32_t &num_feat, int32_t num_suppvec, int32_t* IDX,
00194             float64_t* alphas);
00195 
00200         void set_use_dict_diagonal_optimization(bool flag)
00201         {
00202             use_dict_diagonal_optimization=flag;
00203         }
00204 
00209         bool get_use_dict_diagonal_optimization()
00210         {
00211             return use_dict_diagonal_optimization;
00212         }
00213         
00214     protected:
00223         inline virtual float64_t compute(int32_t idx_a, int32_t idx_b)
00224         {
00225             return compute_helper(idx_a, idx_b, false);
00226         }
00227 
00235         virtual float64_t compute_helper(
00236             int32_t idx_a, int32_t idx_b, bool do_sort);
00237 
00243         virtual float64_t compute_diag(int32_t idx_a);
00244 
00245     protected:
00247         int32_t dictionary_size;
00250         float64_t* dictionary_weights;
00251 
00253         bool use_sign;
00254 
00256         bool use_dict_diagonal_optimization;
00258         int32_t* dict_diagonal_optimization;
00259 };
00260 
00261 #endif /* _COMMWORDSTRINGKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation