00001 #ifndef clsfy_binary_hyperplane_logit_builder_h 00002 #define clsfy_binary_hyperplane_logit_builder_h 00003 //: 00004 // \file 00005 // \brief Linear classifier builder using a logit loss function 00006 // \author Tim Cootes 00007 // \date 18 Jul 2009 00008 00009 #include <clsfy/clsfy_binary_hyperplane_ls_builder.h> 00010 #include <vnl/io/vnl_io_vector.h> 00011 #include <vnl/vnl_vector.h> 00012 #include <vcl_string.h> 00013 #include <vcl_iosfwd.h> // for std::ostream 00014 00015 //======================================================================= 00016 00017 00018 //: Linear classifier builder using a logit loss function 00019 // Finds hyperplane and bias to minimise a cost function which minimises 00020 // the sum of log(pr(error)), ie 00021 // 00022 // alpha*|w|^2 - sum log[(1-minp)logit(c_i * (b+w.x_i)) + minp] 00023 // 00024 // Where c_i is +/-1, x_i is the training vector and minp is a lower bound on 00025 // output probability. 00026 // This focuses attention on points near boundary. 00027 class clsfy_binary_hyperplane_logit_builder : public clsfy_binary_hyperplane_ls_builder 00028 { 00029 private: 00030 //: Weighting on regularisation term 00031 double alpha_; 00032 00033 //: Min prob to be returned by classifier 00034 double min_p_; 00035 public: 00036 00037 // Dflt ctor 00038 clsfy_binary_hyperplane_logit_builder(); 00039 00040 //: Weighting on regularisation term 00041 void set_alpha(double a); 00042 00043 //: Min prob to be returned by classifier 00044 void set_min_p(double p); 00045 00046 //: Build a linear classifier, with the given data. 00047 // Return the mean error over the training set. 00048 // Builds by minimising clsfy_logit_loss_function() with given inputs, 00049 // and a regularisation term using clsfy_quad_regulariser 00050 double build(clsfy_classifier_base &classifier, 00051 mbl_data_wrapper<vnl_vector<double> > &inputs, 00052 const vcl_vector<unsigned> &outputs) const; 00053 00054 //: Build model from data 00055 // Return the mean error over the training set. 00056 // For this classifiers, you must nClasses==1 to indicate a binary classifier 00057 virtual double build(clsfy_classifier_base& model, 00058 mbl_data_wrapper<vnl_vector<double> >& inputs, 00059 unsigned nClasses, 00060 const vcl_vector<unsigned> &outputs) const; 00061 00062 //: Version number for I/O 00063 short version_no() const; 00064 00065 //: Name of the class 00066 vcl_string is_a() const; 00067 00068 //: Name of the class 00069 virtual bool is_class(vcl_string const& s) const; 00070 00071 //: Print class to os 00072 void print_summary(vcl_ostream& os) const; 00073 00074 //: Create a deep copy. 00075 // client is responsible for deleting returned object. 00076 virtual clsfy_builder_base* clone() const; 00077 00078 virtual void b_write(vsl_b_ostream &) const; 00079 virtual void b_read(vsl_b_istream &); 00080 }; 00081 00082 #endif // clsfy_binary_hyperplane_logit_builder_h