contrib/mul/clsfy/clsfy_binary_threshold_1d_builder.h
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_binary_threshold_1d_builder.h
00002 #ifndef clsfy_binary_threshold_1d_builder_h_
00003 #define clsfy_binary_threshold_1d_builder_h_
00004 //:
00005 // \file
00006 // \brief Describe a concrete classifier builder for scalar data
00007 // \author Tim Cootes
00008 
00009 #include <clsfy/clsfy_builder_1d.h>
00010 #include <vcl_string.h>
00011 #include <vcl_iosfwd.h>
00012 #include <vnl/vnl_vector.h>
00013 #include <vbl/vbl_triple.h>
00014 
00015 class clsfy_classifier_1d;
00016 
00017 //: Base for classes to build clsfy_classifier_1d objects
00018 class clsfy_binary_threshold_1d_builder : public clsfy_builder_1d
00019 {
00020  public:
00021 
00022   // Dflt ctor
00023   clsfy_binary_threshold_1d_builder();
00024 
00025   // Destructor
00026   virtual ~clsfy_binary_threshold_1d_builder();
00027 
00028   //: Create empty model
00029   virtual clsfy_classifier_1d* new_classifier() const;
00030 
00031 
00032   //: Build a binary_threshold classifier
00033   //  Train classifier, returning weighted error
00034   //  Selects parameters of classifier which best separate examples from two classes,
00035   //  weighting examples appropriately when estimating the misclassification rate.
00036   //  Returns weighted sum of error, e.wts, where e_i =0 for correct classifications,
00037   //  e_i=1 for incorrect.
00038   virtual double build(clsfy_classifier_1d& classifier,
00039                        const vnl_vector<double>& egs,
00040                        const vnl_vector<double>& wts,
00041                        const vcl_vector<unsigned> &outputs) const;
00042 
00043   //: Build a binary_threshold classifier
00044   // Train classifier, returning weighted error
00045   //  Selects parameters of classifier which best separate examples from two classes,
00046   //  weighting examples appropriately when estimating the misclassification rate.
00047   //  Returns weighted sum of error, e.wts, where e_i =0 for correct classifications,
00048   //  e_i=1 for incorrect.
00049   virtual double build(clsfy_classifier_1d& classifier,
00050                        vnl_vector<double>& egs0,
00051                        vnl_vector<double>& wts0,
00052                        vnl_vector<double>& egs1,
00053                        vnl_vector<double>& wts1) const;
00054 
00055   //: Train classifier, returning weighted error
00056   //  Selects parameters of classifier which best separate examples,
00057   //  weighting examples appropriately when estimating the misclassification rate.
00058   //  data[i] is a triple, {value,class_number,weight}
00059   //  Returns weighted sum of error.
00060   //  Note that input "data" must be sorted to use this routine
00061   virtual double build_from_sorted_data(clsfy_classifier_1d& classifier,
00062                                         const vbl_triple<double,int,int> *data,
00063                                         const vnl_vector<double>& wts) const;
00064 
00065   //: Name of the class
00066   virtual vcl_string is_a() const;
00067 
00068   //: Name of the class
00069   virtual bool is_class(vcl_string const& s) const;
00070 
00071   //: Version number for I/O
00072   short version_no() const;
00073 
00074   //: Create a copy on the heap and return base class pointer
00075   virtual clsfy_builder_1d* clone() const;
00076 
00077   //: Print class to os
00078   virtual void print_summary(vcl_ostream& os) const;
00079 
00080   //: Save class to binary file stream
00081   virtual void b_write(vsl_b_ostream& bfs) const;
00082 
00083   //: Load class from binary file stream
00084   virtual void b_read(vsl_b_istream& bfs);
00085 };
00086 
00087 //: Binary file stream output operator for class reference
00088 void vsl_b_write(vsl_b_ostream& bfs, const clsfy_binary_threshold_1d_builder& b);
00089 
00090 //: Binary file stream input operator for class reference
00091 void vsl_b_read(vsl_b_istream& bfs, clsfy_binary_threshold_1d_builder& b);
00092 
00093 //: Stream output operator for class reference
00094 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_binary_threshold_1d_builder& b);
00095 
00096 //: Stream output operator for class pointer
00097 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_binary_threshold_1d_builder* b);
00098 
00099 #endif // clsfy_binary_threshold_1d_builder_h_