contrib/mul/clsfy/clsfy_smo_1.h
Go to the documentation of this file.
00001 #ifndef clsfy_smo_1_h_
00002 #define clsfy_smo_1_h_
00003 
00004 //:
00005 // \file
00006 // \author Ian Scott
00007 // \date 26-Nov-2001
00008 // \brief Sequential Minimum Optimisation algorithm
00009 
00010 #include <clsfy/clsfy_smo_base.h>
00011 
00012 //: A sequential minimal optimisation for certain restricted quadratic problems.
00013 // This finds the optimal point on a quadratic function constrained by
00014 // inequality bounds on each parameter, and a single equality constraint.
00015 // The is the class of problems associated with Support Vector Machines
00016 // Uses linear kernel operator.
00017 class clsfy_smo_1_lin: public clsfy_smo_base
00018 {
00019  protected:
00020 
00021   //: upper bound on Lagrange multipliers
00022   double C_;
00023 
00024   //: Attempt to jointly optimise Lagrange multipliers i1, and i2.
00025   // \param i1 first Lagrange multiplier.
00026   // \param i2 second Lagrange multiplier.
00027   // \param E1 The amount by which i1 violates KKT conditions.
00028   virtual int take_step(int i1, int i2, double E1);
00029 
00030   //: Attempt to optimise sample i1.
00031   // This attempts to find another value i2,
00032   // in order to jointly optimise both.
00033   virtual int examine_example(int i1);
00034 
00035   //: Calculate the kernel for data items i1 and i2.
00036   virtual double kernel(int i1, int i2);
00037 
00038  public:
00039 
00040   //: Takes a copy of the data wrapper, but not the data.
00041   // Be careful not to destroy the underlying data while using this object.
00042   void set_data(const mbl_data_wrapper<vnl_vector<double> >& data, const vcl_vector<int>& targets);
00043 
00044   // Upper bounds on each parameter.
00045   double C() const;
00046 
00047   //: Set the upper bound on the Lagrange multipliers
00048   void set_C( double C);
00049 
00050   clsfy_smo_1_lin();
00051 
00052   //: Run the optimisation
00053   virtual int calc();
00054 };
00055 
00056 //: A sequential minimal optimisation for certain restricted quadratic problems.
00057 // This finds the optimal point on a quadratic function constrained by
00058 // inequality bounds on each parameter, and a single equality constraint.
00059 // The is the class of problems associated with Support Vector Machines.
00060 // Uses RBF kernel operator.
00061 class clsfy_smo_1_rbf: public clsfy_smo_1_lin
00062 {
00063  protected:
00064 
00065   //: -0.5 sigma^-2, where sigma is the width of the Gaussian kernel
00066   double gamma_;
00067 
00068   //: Calculate the kernel for data items i1 and i2
00069   virtual double kernel(int i1, int i2);
00070 
00071  public:
00072 
00073   //: -0.5 sigma^-2, where sigma is the width of the Gaussian kernel
00074   double gamma() const;
00075 
00076   //: Control sigma, the width of the Gaussian kernel.
00077   // gamma = -0.5 sigma^-2
00078   void set_gamma(double gamma);
00079 
00080   clsfy_smo_1_rbf();
00081 
00082   //: Run the optimisation
00083   virtual int calc();
00084 };
00085 
00086 #endif // clsfy_smo_1_h_