SalzbergWordStringKernel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef _SALZBERGWORDSTRINGKERNEL_H___
00012 #define _SALZBERGWORDSTRINGKERNEL_H___
00013
00014 #include "lib/common.h"
00015 #include "kernel/StringKernel.h"
00016 #include "classifier/PluginEstimate.h"
00017 #include "features/StringFeatures.h"
00018
00027 class CSalzbergWordStringKernel: public CStringKernel<uint16_t>
00028 {
00029 public:
00036 CSalzbergWordStringKernel(int32_t size, CPluginEstimate* pie, CLabels* labels=NULL);
00037
00045 CSalzbergWordStringKernel(
00046 CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r,
00047 CPluginEstimate *pie, CLabels* labels=NULL);
00048
00049 virtual ~CSalzbergWordStringKernel();
00050
00056 void set_prior_probs(float64_t pos_prior_, float64_t neg_prior_)
00057 {
00058 pos_prior=pos_prior_ ;
00059 neg_prior=neg_prior_ ;
00060 if (fabs(pos_prior+neg_prior-1)>1e-6)
00061 SG_WARNING( "priors don't sum to 1: %f+%f-1=%f\n", pos_prior, neg_prior, pos_prior+neg_prior-1) ;
00062 };
00063
00068 void set_prior_probs_from_labels(CLabels* labels);
00069
00076 virtual bool init(CFeatures* l, CFeatures* r);
00077
00079 virtual void cleanup();
00080
00086 bool load_init(FILE* src);
00087
00093 bool save_init(FILE* dest);
00094
00099 virtual EKernelType get_kernel_type() { return K_SALZBERG; }
00100
00105 virtual const char* get_name() const { return "Salzberg" ; }
00106
00107 protected:
00116 float64_t compute(int32_t idx_a, int32_t idx_b);
00117
00118
00125 inline int32_t compute_index(int32_t position, uint16_t symbol)
00126 {
00127 return position*num_symbols+symbol;
00128 }
00129
00130 protected:
00132 CPluginEstimate* estimate;
00133
00135 float64_t* mean;
00137 float64_t* variance;
00138
00140 float64_t* sqrtdiag_lhs;
00142 float64_t* sqrtdiag_rhs;
00143
00145 float64_t* ld_mean_lhs;
00147 float64_t* ld_mean_rhs;
00148
00150 int32_t num_params;
00152 int32_t num_symbols;
00154 float64_t sum_m2_s2;
00156 float64_t pos_prior;
00158 float64_t neg_prior;
00160 bool initialized;
00161 };
00162
00163 #endif