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

📄 svmfusvmbase.h

📁 This is SvmFu, a package for training and testing support vector machines (SVMs). It s written in C
💻 H
字号:
//     This is a part of the SvmFu library, a library for training Support //     Vector Machines.//     Copyright (C) 2000  rif and MIT////     Contact: rif@mit.edu//     This program is free software; you can redistribute it and/or//     modify it under the terms of the GNU General Public License as//     published by the Free Software Foundation; either version 2 of//     the License, or (at your option) any later version.//     This program is distributed in the hope that it will be useful,//     but WITHOUT ANY WARRANTY; without even the implied warranty of//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the//     GNU General Public License for more details.//     You should have received a copy of the GNU General Public//     License along with this program; if not, write to the Free//     Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,//     MA 02111-1307 USA#ifndef SVMFU_SVM_BASE_HEADER#define SVMFU_SVM_BASE_HEADERusing namespace std;#include <math.h>#include <iostream>#include <fstream>#include <string>#include <stdio.h>#include <stdlib.h>#include "SvmFuSvmConstants.h"#include "SvmFuSvmTypedefs.h"// This is the BASE SvmFu class, used for representing an SVM.  It// maintains a feasible vector of alphas, and keeps track of the set// of SVs and USVs.  It does NOT do any caching, so the operation of// changing an alpha is FAST.  It has to iterate over the entire set// of SVs to compute the output at a training example or a new point,// and therefore this will be slow.// Don't use this for training purposes; more useful, specialized classes// can be derived from it.  For testing, this is probably all you can do,// so we'll provide a "read from file" constructor.// Invariants and Notes: // 1.  This class maintains feasibility of the dual optimal solution at all //     times.// 2.  Static data (training sets, y vectors) are NOT copied,//     and the programmer must maintain their integrity (don't let them be//     automatics that pass out of scope.  Vectors of //     alphas or C or supVecIDs ARE in general copied.// 3.  KernVal must be convertible to double by an implicit conversion.template <class DataPt, class KernVal> class SvmBase {public:  // The normal constructor.  SvmBase(int svmSize,	  const IntVec y,	  DataPt *trnSetPtr,	  const KernVal (*kernProdFuncPtr)(const DataPt &pt1,					   const DataPt &pt2),	  double C=10, double eps = 10E-12);      virtual ~SvmBase();  int classifyDataPt(const DataPt &pt) const;   virtual double outputAtDataPt(const DataPt &pt) const;      int classifyTrainingExample(int ex) const;  virtual double outputAtTrainingExample(int ex) const;   double computeTrainingSetPerf(bool printInfo=true) const;  virtual double dualObjFunc() const;    KernVal kernProd(int ex1, int ex2) const;  const DataPt getTrainingExample(int ex) const;  bool supVecP(int ex) const;  bool unbndSupVecP(int ex) const;  bool everSV_P(int ex) const;  int getNumSupVecs() const;  int getNumUnbndSupVecs() const;  int getNumEverSV() const;  IntVec getSupVecIDs() const; // COPY  IntVec getSupVecIDsPtr() const;  IntVec getUnbndSupVecIDs() const;  // COPY  IntVec getUnbndSupVecIDsPtr() const;   virtual void setAlpha(int ex, double newAlpha);  void setAllAlphas(const DoubleVec alphas); // Alpha vec is COPIED  double getAlpha(int ex) const;  DoubleVec getAllAlphas() const; // COPY  DoubleVec getSupVecAlphas() const; // COPY  DoubleVec getUnbndSupVecAlphas() const; // COPY      virtual void setB(double b);  double getB() const;      // void setEpsilon(double eps);  NOT USEFUL.  Irritating to maintain  // the data structures.  For now, we'll force epsilon to be set at  // object creation time.  double getEpsilon() const;  void setAllC(double c);  void setPosNegC(double posC, double negC);  void setCVec(const DoubleVec cVec); // COPY  virtual void setC(int ex, double newC);  DoubleVec getCVec() const; // COPY  double getC(int ex) const;      int getSize() const;  int getY(int ex) const { return y_[ex]; }protected:  const KernVal(*kernProdFuncPtr_) (const DataPt &pt1, const DataPt &pt2);      void initSvmBase(double C);      void addToUnbndSet(int ex);  void removeFromUnbndSet(int ex);      void addToSV_Set(int ex);  void removeFromSV_Set(int ex);  const int svmSize_;  const IntVec y_;  const DataPt *trnSetPtr_;    int numSupVecs_;  int numUnbndSupVecs_;  DoubleVec cVec_;  DoubleVec alphas_;  double b_;    double eps_;  IntVec unbndSet_, unbndPos_;  IntVec SV_Set_, SV_Pos_;  BoolVec everSV_P_;      int numEverSV_;      // We have no interest in copies.  SvmBase(const SvmBase&);  SvmBase& operator= (const SvmBase&);};#endif // SVMFU_SVM_BASE_HEADER

⌨️ 快捷键说明

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