MindyGramKernel.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "lib/config.h"
00012
00013 #ifdef HAVE_MINDY
00014
00015 #include <mindy.h>
00016
00017 #ifndef _MINDYGRAMKERNEL_H___
00018 #define _MINDYGRAMKERNEL_H___
00019
00020 #include "lib/common.h"
00021 #include "kernel/Kernel.h"
00022
00023
00024 #define NO_SICO -1
00025
00026
00027 typedef struct {
00028 char *name;
00029 int idx;
00030 double val;
00031 char *descr;
00032 } param_spec_t;
00033
00034 class CMindyGramKernel: public CKernel
00035 {
00036 public:
00037
00038 CMindyGramKernel(INT ch, CHAR *measure, DREAL width);
00039 CMindyGramKernel(CFeatures *l, CFeatures *r, CHAR *measure, DREAL width);
00040 virtual ~CMindyGramKernel();
00041
00042
00043 void set_param(CHAR *param);
00044
00045 void set_md5cache(INT c);
00046
00047 void set_norm(ENormalizationType e);
00048
00049
00050 void parse_params(CHAR *);
00051 virtual bool init(CFeatures* l, CFeatures* r);
00052 virtual void cleanup();
00053 virtual void remove_lhs();
00054 virtual void remove_rhs();
00055
00056
00057 inline virtual EKernelType get_kernel_type() { return K_MINDYGRAM; }
00058 inline virtual EFeatureType get_feature_type() { return F_ULONG; }
00059 inline virtual EFeatureClass get_feature_class() { return C_MINDYGRAM; }
00060 inline virtual const CHAR* get_name() { return "MindyGram"; }
00061
00062
00063 virtual bool init_optimization(INT count, INT *IDX, DREAL * weights);
00064 virtual bool delete_optimization();
00065 virtual DREAL compute_optimized(INT idx);
00066 virtual void add_to_normal(INT idx, DREAL weight);
00067 virtual void clear_normal();
00068
00069
00070 bool load_init(FILE* src);
00071 bool save_init(FILE* dest);
00072
00073
00074 inline DREAL normalize_weight(DREAL v, INT i, ENormalizationType n) {
00075 switch (n) {
00076 case NO_NORMALIZATION:
00077 return v;
00078 case SQRT_NORMALIZATION:
00079 return v / sqrt(sdiag_lhs[i]);
00080 case FULL_NORMALIZATION:
00081 return v / sdiag_lhs[i];
00082 default:
00083 ASSERT(0);
00084 }
00085 return -CMath::INFTY;
00086 }
00087
00088 protected:
00089
00090 DREAL compute(INT idx_a, INT idx_b);
00091
00092 private:
00093
00094 DREAL* sdiag_lhs;
00095 DREAL* sdiag_rhs;
00096
00097
00098 CHAR *measure;
00099
00100 bool initialized;
00101
00102 sico_t simcof;
00103
00104 ENormalizationType norm;
00105
00106 sm_t *kernel;
00107
00108 gram_t *normal;
00109
00110 size_t cache;
00111
00112 DREAL width;
00113
00114 };
00115 #endif
00116 #endif