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
00025 class CSalzbergWordStringKernel: public CStringKernel<uint16_t>
00026 {
00027 public:
00034 CSalzbergWordStringKernel(int32_t size, CPluginEstimate* pie, CLabels* labels=NULL);
00035
00043 CSalzbergWordStringKernel(
00044 CStringFeatures<uint16_t>* l, CStringFeatures<uint16_t>* r,
00045 CPluginEstimate *pie, CLabels* labels=NULL);
00046
00047 virtual ~CSalzbergWordStringKernel();
00048
00054 void set_prior_probs(float64_t pos_prior_, float64_t neg_prior_)
00055 {
00056 pos_prior=pos_prior_ ;
00057 neg_prior=neg_prior_ ;
00058 if (fabs(pos_prior+neg_prior-1)>1e-6)
00059 SG_WARNING( "priors don't sum to 1: %f+%f-1=%f\n", pos_prior, neg_prior, pos_prior+neg_prior-1) ;
00060 };
00061
00066 void set_prior_probs_from_labels(CLabels* labels);
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_SALZBERG; }
00098
00103 virtual const char* get_name() { return "Salzberg" ; }
00104
00105 protected:
00114 float64_t compute(int32_t idx_a, int32_t idx_b);
00115
00116
00123 inline int32_t compute_index(int32_t position, uint16_t symbol)
00124 {
00125 return position*num_symbols+symbol;
00126 }
00127
00128 protected:
00130 CPluginEstimate* estimate;
00131
00133 float64_t* mean;
00135 float64_t* variance;
00136
00138 float64_t* sqrtdiag_lhs;
00140 float64_t* sqrtdiag_rhs;
00141
00143 float64_t* ld_mean_lhs;
00145 float64_t* ld_mean_rhs;
00146
00148 int32_t num_params;
00150 int32_t num_symbols;
00152 float64_t sum_m2_s2;
00154 float64_t pos_prior;
00156 float64_t neg_prior;
00158 bool initialized;
00159 };
00160
00161 #endif