⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ginikernel.h

📁 一种新的SVM算法
💻 H
字号:
#ifndef _SVM_KERNEL_#define _SVM_KERNEL_/*****************************************************************************/// NAME :  Support Vector Kernel Interface// // DESCRIPTION : Contains the SVM interface to the HMM. It consists of //// USAGE ://// KNOWN BUGS ://// BUG REPORT: shantanu@jhu.edu///*****************************************************************************/#include<ginidefs.h>#include<stdio.h>//---------------------------------------------------------------------------// Gini SVM kernel types// --------------------------------------------------------------------------enum GINISVMKernelType{   GINISVMGAUSSIAN,   GINISVMPOLY,   GINISVMDTK,   GINISVMTANH};//---------------------------------------------------------------------------// Generic kernel type//---------------------------------------------------------------------------class GINI_SVMKernel{   // storage for precomputed kernel if the number of data points   // is less.    GINI_double **cachedata;   // Cache mapping for swapping data pointers and   // replacing the kernel rows in and out of the   // cache.   GINI_u32 *cachemap;   // Cache size   GINI_u32 cachesize;   // Training size   GINI_u32 trainsize;   // Current cache size   GINI_u32 currentcachesize;   // Total active elements   GINI_u32 totalactive;   // Activity counter   GINI_u32 *activity;   // Reverse mapping from cache-id to data-id   GINI_u32 *reversemap;   // Errno for the kernel class   GINI_ERROR_VAL ginierr;   protected:   // Counts the number of kernel evaluations.   GINI_u32  evaluations;      // Counts the number of kernel evaluations.   GINI_u32  swapcounter;      public:   // Constructor   GINI_SVMKernel() { evaluations = 0; cachesize = 0; currentcachesize = 0;}   // Destructor   virtual ~GINI_SVMKernel();   // Virtual function that has to be defined by all kernels which   // inherit this base class.   virtual GINI_double Value( GINI_double* a, GINI_double* b, GINI_u32 dim ) = 0;   GINI_double Value( GINI_double **traindata, 		     GINI_u32 a, 		     GINI_u32 b,		     GINI_u32 dim		   );   // Get the kernel id to identify the kind of kernel used.   virtual GINISVMKernelType GetId() = 0;   // Get the kernel id to identify the kind of kernel used.   virtual GINI_bool Write( FILE* output ) = 0;    virtual GINI_bool Read( FILE* output ) = 0;    virtual GINI_bool spflag() = 0;    // Computes all the kernel values given the training data   // and the number of training points.   GINI_bool ComputeAll( GINI_double** training, GINI_u32 dim);   // Returns the number of time kernels have been computed.   GINI_u32 Evaluations() { return evaluations; }   // Returns the number of time kernels have been computed.   GINI_u32 Swapcount() { return swapcounter; }   // Resets the kernel and releases its cache   void Reset();    // Returns all the internal pointers if one    // wishes to do C style programming.   GINI_double** Bufferptr() { return cachedata; }   GINI_u32 *CacheMapptr() { return cachemap; }   // Returns true if data is present in the   // cache.   GINI_bool Ispresent( GINI_u32 a ) { return (cachemap[a] > 0) ? GINI_TRUE : GINI_FALSE; }   // Inserts a fresh data into the cache.   GINI_bool InsertCache( GINI_u32 a );    // Inserts a fresh data into the cache.   GINI_bool ResetActivity( GINI_u32 a );    // Initializes the kernel and bootstrap the   // cache memory.   GINI_bool InitializeCache( GINI_u32 inpsize, GINI_u32 inptrain );   // Returns the size of the cache.   GINI_u32 GetCachesize() { return cachesize; }};//---------------------------------------------------------------------------//  Gaussian Kernel Interface implementing//  K(\x,\y) = exp(-gamma*||x-y||^2)//---------------------------------------------------------------------------class GINI_GaussianKernel : public GINI_SVMKernel{   GINI_double gamma;   GINI_bool sparseflag;   public:   GINI_GaussianKernel( GINI_double gamma, GINI_bool inpflag);   virtual ~GINI_GaussianKernel() {}   GINI_double Value( GINI_double* a, GINI_double* b, GINI_u32 dim );   GINISVMKernelType GetId() { return GINISVMGAUSSIAN; }   GINI_bool Write( FILE* output );    GINI_bool Read( FILE* output );    GINI_bool spflag() { return sparseflag; } };//---------------------------------------------------------------------------//  Polynomial Kernel Interface implementing//  K(\x,\y) = (offset + scale*(x'y))^power;//---------------------------------------------------------------------------class GINI_PolyKernel : public GINI_SVMKernel{   GINI_double scale;   GINI_double offset;   GINI_u32  power;   GINI_bool sparseflag;   public:   GINI_PolyKernel( GINI_double inpscale, GINI_u32 inppower, GINI_bool inpflag );   GINI_PolyKernel( GINI_double inpoffset,GINI_double inpscale, GINI_u32 inppower, GINI_bool inpflag );   virtual ~GINI_PolyKernel() {}   GINI_double Value( GINI_double* a, GINI_double* b, GINI_u32 dim );   GINISVMKernelType GetId() { return GINISVMPOLY; }   GINI_bool Write( FILE* output );    GINI_bool Read( FILE* output );    GINI_bool spflag() { return sparseflag; } };class GINI_DTKKernel : public GINI_SVMKernel{   GINI_double scale;             // scale factor   GINI_double penaltyid;         // insertion-del penatly   GINI_double penaltysame;       // penatly for same insertions.   GINI_double penaltysb;         // substitution penalty   public:   GINI_DTKKernel( GINI_double inpscale, 		   GINI_double inppenaltyid,		   GINI_double inppenaltysame,		   GINI_double inppenaltysb		 );   virtual ~GINI_DTKKernel() {}   // For String and DTK kernel the dim parameter is = 0   // and the dimension information for each vector is stored   // in the header of the vector.   GINI_double Value( GINI_double* a, GINI_double* b, GINI_u32 dim );   GINISVMKernelType GetId() { return GINISVMDTK; }   GINI_bool Write( FILE* output );    GINI_bool Read( FILE* output );    GINI_bool spflag() { return GINI_FALSE; } };//---------------------------------------------------------------------------//  Tanh Kernel Interface implementing//  K(\x,\y) = tanh(scale*(x'y));//---------------------------------------------------------------------------class GINI_TanhKernel : public GINI_SVMKernel{  GINI_double scale;  GINI_bool sparseflag; public:  GINI_TanhKernel( GINI_double inpscale, GINI_bool inpflag );  ~GINI_TanhKernel() {}  GINI_double Value( GINI_double* a, GINI_double* b, GINI_u32 dim );  GINISVMKernelType GetId() { return GINISVMTANH; }  GINI_bool Write( FILE* output );   GINI_bool Read( FILE* output );   GINI_bool spflag() { return sparseflag; } };#endif   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -