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 
00044 class CCommWordStringKernel : public CStringKernel<uint16_t>
00045 {
00046     friend class CSqrtDiagKernelNormalizer;
00047     friend class CAvgDiagKernelNormalizer;
00048     friend class CFirstElementKernelNormalizer;
00049     friend class CTanimotoKernelNormalizer;
00050     friend class CDiceKernelNormalizer;
00051 
00052     public:
00058         CCommWordStringKernel(int32_t size, bool use_sign);
00059 
00067         CCommWordStringKernel(
00068             CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r,
00069             bool use_sign=false, int32_t size=10);
00070 
00071         virtual ~CCommWordStringKernel();
00072 
00079         virtual bool init(CFeatures* l, CFeatures* r);
00080 
00082         virtual void cleanup();
00083 
00089         bool load_init(FILE* src);
00090 
00096         bool save_init(FILE* dest);
00097 
00102         virtual EKernelType get_kernel_type() { return K_COMMWORDSTRING; }
00103 
00108         virtual const char* get_name() const { return "CommWordString"; }
00109 
00114         virtual bool init_dictionary(int32_t size);
00115 
00123         virtual bool init_optimization(
00124             int32_t count, int32_t *IDX, float64_t* weights);
00125 
00130         virtual bool delete_optimization();
00131 
00137         virtual float64_t compute_optimized(int32_t idx);
00138 
00144         virtual void add_to_normal(int32_t idx, float64_t weight);
00145 
00147         virtual void clear_normal();
00148 
00153         inline virtual EFeatureType get_feature_type() { return F_WORD; }
00154 
00160         void get_dictionary(int32_t& dsize, float64_t*& dweights)
00161         {
00162             dsize=dictionary_size;
00163             dweights = dictionary_weights;
00164         }
00165 
00178         virtual float64_t* compute_scoring(
00179             int32_t max_degree, int32_t& num_feat, int32_t& num_sym,
00180             float64_t* target, int32_t num_suppvec, int32_t* IDX,
00181             float64_t* alphas, bool do_init=true);
00182 
00191         char* compute_consensus(
00192             int32_t &num_feat, int32_t num_suppvec, int32_t* IDX,
00193             float64_t* alphas);
00194 
00199         void set_use_dict_diagonal_optimization(bool flag)
00200         {
00201             use_dict_diagonal_optimization=flag;
00202         }
00203 
00208         bool get_use_dict_diagonal_optimization()
00209         {
00210             return use_dict_diagonal_optimization;
00211         }
00212         
00213     protected:
00222         inline virtual float64_t compute(int32_t idx_a, int32_t idx_b)
00223         {
00224             return compute_helper(idx_a, idx_b, false);
00225         }
00226 
00234         virtual float64_t compute_helper(
00235             int32_t idx_a, int32_t idx_b, bool do_sort);
00236 
00242         virtual float64_t compute_diag(int32_t idx_a);
00243 
00244     protected:
00246         int32_t dictionary_size;
00249         float64_t* dictionary_weights;
00250 
00252         bool use_sign;
00253 
00255         bool use_dict_diagonal_optimization;
00257         int32_t* dict_diagonal_optimization;
00258 };
00259 
00260 #endif /* _COMMWORDSTRINGKERNEL_H__ */

SHOGUN Machine Learning Toolbox - Documentation