contrib/mul/clsfy/clsfy_rbf_svm_smo_1_builder.h
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_rbf_svm_smo_1_builder.h
00002 // Copyright: (C) 2001 British Telecommunications plc.
00003 #ifndef clsfy_rbf_svm_smo_1_builder_h_
00004 #define clsfy_rbf_svm_smo_1_builder_h_
00005 //:
00006 // \file
00007 // \brief Describe an interface to an SMO SVM builder and additional logic
00008 // \author Ian Scott
00009 // \date Dec 2001
00010 
00011 #include <clsfy/clsfy_builder_base.h>
00012 #include <clsfy/clsfy_rbf_svm.h>
00013 #include <vnl/vnl_vector.h>
00014 #include <mbl/mbl_data_wrapper.h>
00015 #include <vcl_iosfwd.h>
00016 
00017 //: Base for classes to build clsfy_classifier_base objects
00018 class clsfy_rbf_svm_smo_1_builder : public clsfy_builder_base
00019 {
00020   //: C, the upper bound on the Lagrange multipliers.
00021   // 0 means no (or infinite) upper bound.
00022   double boundC_;
00023 
00024   //: Width of Gaussian function
00025   double rbf_width_;
00026 
00027  public:
00028 
00029   //: Dflt ctor
00030    clsfy_rbf_svm_smo_1_builder(): boundC_(0), rbf_width_(1.0) {}
00031 
00032   //: Create empty model
00033   clsfy_classifier_base* new_classifier() const{return new clsfy_rbf_svm();}
00034 
00035   //: Build model from data
00036   // returns the empirical error, or +INF if there is an error.
00037   // nclasses should be 1. The members of outputs() should be 0 or 1.
00038   double build(clsfy_classifier_base& classifier,
00039                mbl_data_wrapper<vnl_vector<double> >& inputs,
00040                unsigned nClasses,
00041                const vcl_vector<unsigned> &outputs) const;
00042 
00043   //: Build a classifier from data.
00044   // returns the empirical error rate, or +INF if there is an error.
00045   // The members of outputs() should be 0 or 1.
00046   double build(clsfy_classifier_base& classifier,
00047                mbl_data_wrapper<vnl_vector<double> >& inputs,
00048                const vcl_vector<unsigned> &outputs) const;
00049 
00050   //: Radius of Gaussian function
00051   double rbf_width() const;
00052 
00053   //: Set the Radius of Gaussian function
00054   void set_rbf_width(double);
00055 
00056   //: Set C, the upper bound on the Lagrange multipliers
00057   // 0 means no (or infinite) upper bound and is the default.
00058   // A finite value effectively allows the training data to encroach into
00059   // the separating margin. Smaller C -> smoother boundary
00060   void set_bound_on_multipliers(double C)
00061   { boundC_ = C; }
00062 
00063 
00064   //: The upper bound on the Lagrange multipliers
00065   // 0 means no (or infinite) upper bound.
00066   // A finite value effectively allows the training data to encroach into
00067   // the separating margin. Smaller C -> smoother boundary
00068   double bound_on_multipliers() const
00069   { return boundC_; }
00070 
00071   //: Name of the class
00072   vcl_string is_a() const;
00073 
00074   //: Name of the class
00075   bool is_class(vcl_string const& s) const;
00076 
00077   //: Return the class's IO version number
00078   short version_no() const;
00079 
00080   //: Create a copy on the heap and return base class pointer
00081   clsfy_builder_base* clone() const;
00082 
00083   //: Print class to os
00084   void print_summary(vcl_ostream& os) const;
00085 
00086   //: Save class to binary file stream
00087   void b_write(vsl_b_ostream& bfs) const;
00088 
00089   //: Load class from binary file stream
00090   void b_read(vsl_b_istream& bfs);
00091 
00092   //: Config from a stream.
00093   void config(vcl_istream&);
00094 };
00095 
00096 #endif // clsfy_rbf_svm_smo_1_builder_h_