contrib/mul/clsfy/clsfy_builder_1d.h

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

Generated on Thu Jan 8 05:11:33 2009 for contrib/mul/clsfy by  doxygen 1.5.1