SalzbergWordKernel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _SALZBERGWORDKERNEL_H___
00012 #define _SALZBERGWORDKERNEL_H___
00013
00014 #include "lib/common.h"
00015 #include "kernel/StringKernel.h"
00016 #include "classifier/PluginEstimate.h"
00017 #include "features/StringFeatures.h"
00018
00020 class CSalzbergWordKernel: public CStringKernel<WORD>
00021 {
00022 public:
00028 CSalzbergWordKernel(INT size, CPluginEstimate* pie);
00029
00036 CSalzbergWordKernel(
00037 CStringFeatures<WORD>* l, CStringFeatures<WORD>* r,
00038 CPluginEstimate *pie);
00039
00040 virtual ~CSalzbergWordKernel();
00041
00047 void set_prior_probs(DREAL pos_prior_, DREAL neg_prior_)
00048 {
00049 pos_prior=pos_prior_ ;
00050 neg_prior=neg_prior_ ;
00051 if (fabs(pos_prior+neg_prior-1)>1e-6)
00052 SG_WARNING( "priors don't sum to 1: %f+%f-1=%f\n", pos_prior, neg_prior, pos_prior+neg_prior-1) ;
00053 };
00054
00061 virtual bool init(CFeatures* l, CFeatures* r);
00062
00064 virtual void cleanup();
00065
00071 bool load_init(FILE* src);
00072
00078 bool save_init(FILE* dest);
00079
00084 virtual EKernelType get_kernel_type() { return K_SALZBERG; }
00085
00090 virtual const CHAR* get_name() { return "Salzberg" ; }
00091
00092 protected:
00101 DREAL compute(INT idx_a, INT idx_b);
00102
00103
00110 inline INT compute_index(INT position, WORD symbol)
00111 {
00112 return position*num_symbols+symbol;
00113 }
00114
00115 protected:
00117 CPluginEstimate* estimate;
00118
00120 DREAL* mean;
00122 DREAL* variance;
00123
00125 DREAL* sqrtdiag_lhs;
00127 DREAL* sqrtdiag_rhs;
00128
00130 DREAL* ld_mean_lhs;
00132 DREAL* ld_mean_rhs;
00133
00135 INT num_params;
00137 INT num_symbols;
00139 DREAL sum_m2_s2;
00141 DREAL pos_prior;
00143 DREAL neg_prior;
00145 bool initialized;
00146 };
00147
00148 #endif