📄 kernelfuncs.h
字号:
// Copyright (C) 2000 Ryan M. Rifkin <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./* Kernel function headers. These will be include in both the training * and testing clients. * * We have two kinds of sparse representations: * sparse01 has integers in the nonzero dimensions, all nonzero * values are 1 * sparseN has pairs, where the first value is the number of the dimensions, * the second number is the value. * i.e., to represent a vector that had ones in the 5th and 8th position, * and zeros everywhere else in a dataset with at most four nonzeros per * data point (i.e., you'd feed a dimensionality of 4 to a "linear" specialized * machine): * sparse01: 5 8 -1 -1 * sparseN: 5 1 8 1 -1 -1 *///! Provides all the kernel functions for SvmFu client programs.template<class KernVal, class DataElt> class KernelFuncs{ public: KernelFuncs<KernVal, DataElt> (KernType k_, MachType m_); // dense functions static const inline KernVal linearProduct (const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline void addToW(double *&w, const DataPoint<DataElt> &p, double amt); static const inline double multW(double *w, const DataPoint<DataElt> &p); static const inline KernVal polynomialProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline KernVal gaussianProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); // sparse01 functions static const inline KernVal sparse01InternalProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline KernVal sparse01BinaryProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline void addToWsparse01(double *&w, const DataPoint<DataElt> &p, double amt); static const inline double multWsparse01(double *w, const DataPoint<DataElt> &p); static const inline KernVal sparse01PolynomialProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline KernVal sparse01GaussianProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); // sparseN functions static const inline KernVal sparseNInternalProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline KernVal sparseNLinearProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline void addToWsparseN(double *&w, const DataPoint<DataElt> &p, double amt); static const inline double multWsparseN(double *w, const DataPoint<DataElt> &p); static const inline KernVal sparseNPolynomialProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); static const inline KernVal sparseNGaussianProduct(const DataPoint<DataElt> &p1, const DataPoint<DataElt> &p2); const KernVal (*pfunc) (const DataPoint<DataElt> &, const DataPoint<DataElt> &); const void (*afunc) (double *&w, const DataPoint<DataElt> &, double amt); const double (*mfunc) (double *w, const DataPoint <DataElt> &);};// Global kernel variablesint degree = 2; // for polynomial kernelsdouble offset = 0; // for polynomial kernelsdouble sigma = 1; // for Gaussian kernelsdouble normalizer = 1; // amount to divide kernel products by
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -