00001
00002
00045 #ifndef _KernelFunction_H_
00046 #define _KernelFunction_H_
00047
00048
00049 #include <ReClaM/Model.h>
00050 #include <vector>
00051
00052
00085 class KernelFunction : public Model
00086 {
00087 public:
00089 KernelFunction();
00090
00092 virtual ~KernelFunction();
00093
00094
00096 virtual double eval(const Array<double>& x1, const Array<double>& x2) const = 0;
00097
00100 virtual double evalDerivative(const Array<double>& x1, const Array<double>& x2, Array<double>& derivative) const;
00101
00103 inline double operator()(const Array<double>& x1, const Array<double>& x2)
00104 {
00105 return eval(x1, x2);
00106 }
00107
00111 void model(const Array<double>& input, Array<double> &output);
00112
00115 void modelDerivative(const Array<double>& input, Array<double>& derivative);
00116
00119 void modelDerivative(const Array<double>& input, Array<double> &output, Array<double>& derivative);
00120
00121 friend class C_SVM;
00122 };
00123
00124
00126 class LinearKernel : public KernelFunction
00127 {
00128 public:
00129 LinearKernel();
00130 ~LinearKernel();
00131
00132
00133 double eval(const Array<double>& x1, const Array<double>& x2) const;
00134 double evalDerivative(const Array<double>& x1, const Array<double>& x2, Array<double>& derivative) const;
00135 };
00136
00137
00139 class PolynomialKernel : public KernelFunction
00140 {
00141 public:
00142 PolynomialKernel(int degree, double offset);
00143 ~PolynomialKernel();
00144
00145
00146 double eval(const Array<double>& x1, const Array<double>& x2) const;
00147
00148
00149
00150
00151
00152 void setParameter(unsigned int index, double value);
00153
00154 bool isFeasible();
00155 };
00156
00157
00170 class RBFKernel : public KernelFunction
00171 {
00172 public:
00173 RBFKernel(double gamma);
00174 ~RBFKernel();
00175
00176
00177 double eval(const Array<double>& x1, const Array<double>& x2) const;
00178 double evalDerivative(const Array<double>& x1, const Array<double>& x2, Array<double>& derivative) const;
00179
00180 bool isFeasible();
00181
00182 double getSigma();
00183 void setSigma(double sigma);
00184 };
00185
00186
00188 class NormalizedRBFKernel : public KernelFunction
00189 {
00190 public:
00191 NormalizedRBFKernel();
00192 NormalizedRBFKernel(double s);
00193
00194
00195 void setSigma(double s);
00196 double eval(const Array<double> &x, const Array<double> &z) const;
00197 double evalDerivative(const Array<double> &x, const Array<double> &z, Array<double>& derivative) const;
00198 };
00199
00200
00212 class NormalizedKernel : public KernelFunction
00213 {
00214 public:
00215 NormalizedKernel(KernelFunction* base);
00216 ~NormalizedKernel();
00217
00218
00219 void setParameter(unsigned int index, double value);
00220 double eval(const Array<double>& x1, const Array<double>& x2) const;
00221 double evalDerivative(const Array<double>& x1, const Array<double>& x2, Array<double>& derivative) const;
00222
00223 bool isFeasible();
00224
00225 protected:
00227 KernelFunction* baseKernel;
00228 };
00229
00230
00248 class WeightedSumKernel : public KernelFunction
00249 {
00250 public:
00251 WeightedSumKernel(const std::vector<KernelFunction*>& base);
00252 ~WeightedSumKernel();
00253
00254
00255 void setParameter(unsigned int index, double value);
00256 double eval(const Array<double>& x1, const Array<double>& x2) const;
00257 double evalDerivative(const Array<double>& x1, const Array<double>& x2, Array<double>& derivative) const;
00258
00259 bool isFeasible();
00260
00261 protected:
00263 std::vector<KernelFunction*> baseKernel;
00264
00266 std::vector<double> weight;
00267
00269 double weightsum;
00270 };
00271
00272
00290 class WeightedSumKernel2 : public KernelFunction
00291 {
00292 public:
00293 WeightedSumKernel2(const std::vector<KernelFunction*>& base);
00294 ~WeightedSumKernel2();
00295
00296
00297 void setParameter(unsigned int index, double value);
00298 double eval(const Array<double>& x1, const Array<double>& x2) const;
00299 double evalDerivative(const Array<double>& x1, const Array<double>& x2, Array<double>& derivative) const;
00300
00301 bool isFeasible();
00302
00303 protected:
00304 std::vector<KernelFunction*> baseKernel;
00305
00306 std::vector<double> weight;
00307
00308 double weightsum;
00309 };
00310
00311
00312 #endif
00313