MindyGramKernel.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) 2006 Konrad Rieck
00008  * Copyright (C) 2006-2009 Fraunhofer Institute FIRST and Max-Planck-Society
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 /* Similarity coefficients */
00024 #define NO_SICO         -1
00025 
00026 /* Parameter specifications */
00027 typedef struct {
00028         char *name;         /* Name of parameter */
00029         int32_t idx;        /* Index in param array (see sm.h) */
00030         float64_t val;          /* Default value */
00031         char *descr;        /* Description */
00032 } param_spec_t;
00033 
00034 class CMindyGramKernel: public CKernel
00035 {
00036     public:
00037         /* Constructors */
00038         CMindyGramKernel(int32_t ch, char *measure, float64_t width);
00039         CMindyGramKernel(
00040             CFeatures *l, CFeatures *r, char *measure, float64_t width);
00041         virtual ~CMindyGramKernel();
00042 
00043         /* Set options */
00044         void set_param(char *param);
00045         /* Set MD5 cache size */
00046         void set_md5cache(int32_t c);
00047         /* Set normalization */
00048         void set_norm(ENormalizationType e);
00049 
00050         /* Init and cleanup functions */
00051         void parse_params(char *);
00052         virtual bool init(CFeatures* l, CFeatures* r);
00053         virtual void cleanup();
00054         virtual void remove_lhs();
00055         virtual void remove_rhs();
00056 
00057         /* Identification functions */
00058         inline virtual EKernelType get_kernel_type() { return K_MINDYGRAM; }
00059         inline virtual EFeatureType get_feature_type() { return F_ULONG; }
00060         inline virtual EFeatureClass get_feature_class() { return C_MINDYGRAM; }
00061         inline virtual const char* get_name() const { return "MindyGram"; }
00062 
00063         /* Optimization functions */
00064         virtual bool init_optimization(
00065             int32_t count, int32_t *IDX, float64_t * weights);
00066         virtual bool delete_optimization();
00067         virtual float64_t compute_optimized(int32_t idx);
00068         virtual void add_to_normal(int32_t idx, float64_t weight);
00069         virtual void clear_normal();
00070 
00071         /* Load and ysave functions */
00072         bool load_init(FILE* src);
00073         bool save_init(FILE* dest);
00074 
00075     protected:
00076         /* Kernel function */
00077         float64_t compute(int32_t idx_a, int32_t idx_b);
00078 
00079     private:
00080         /* Name of similartiy measure */
00081         char *measure;
00082         /* Similarity coefficient or 0 */
00083         sico_t simcof;
00084         /* Normalization mode */
00085         ENormalizationType norm;
00086         /* Kernel function (=> Mindy similarity measure) */
00087         sm_t *kernel;
00088         /* Normal vector for optimization */
00089         gram_t *normal;
00090         /* MD5 cache size */
00091         size_t cache;
00092         /* Kernel width */
00093         float64_t width;
00094 
00095 };
00096 #endif /* _MINDYGRAMKERNEL_H__ */
00097 #endif /* HAVE_MINDY */

SHOGUN Machine Learning Toolbox - Documentation