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