00001 // Copyright: (C) 2000 British Telecommunications plc 00002 #ifndef clsfy_builder_base_h_ 00003 #define clsfy_builder_base_h_ 00004 //: 00005 // \file 00006 // \brief Describe an abstract classifier 00007 // \author Ian Scott 00008 // \date 2000-05-10 00009 // \verbatim 00010 // Modifications 00011 // 2 May 2001 IMS Converted to VXL 00012 // \endverbatim 00013 00014 #include <mbl/mbl_data_wrapper.h> 00015 #include <vnl/vnl_vector.h> 00016 #include <vsl/vsl_binary_io.h> 00017 #include <vcl_vector.h> 00018 #include <vcl_string.h> 00019 #include <vcl_memory.h> 00020 #include <vcl_iosfwd.h> 00021 00022 class clsfy_classifier_base; 00023 00024 //: Base for classes to build clsfy_classifier_base objects 00025 class clsfy_builder_base 00026 { 00027 public: 00028 // Destructor 00029 virtual ~clsfy_builder_base() {} 00030 00031 //: Create empty model 00032 virtual clsfy_classifier_base* new_classifier() const = 0; 00033 00034 //: Build model from data 00035 // Return the mean error over the training set. 00036 // For many classifiers, you may use nClasses==1 to 00037 // indicate a binary classifier 00038 virtual double build(clsfy_classifier_base& model, 00039 mbl_data_wrapper<vnl_vector<double> >& inputs, 00040 unsigned nClasses, 00041 const vcl_vector<unsigned> &outputs) const = 0; 00042 00043 //: Name of the class 00044 virtual vcl_string is_a() const; 00045 00046 //: Name of the class 00047 virtual bool is_class(vcl_string const& s) const; 00048 00049 //: Create a copy on the heap and return base class pointer 00050 virtual clsfy_builder_base* clone() const = 0; 00051 00052 //: Print class to os 00053 virtual void print_summary(vcl_ostream& os) const = 0; 00054 00055 //: Save class to binary file stream 00056 virtual void b_write(vsl_b_ostream& bfs) const = 0; 00057 00058 //: Load class from binary file stream 00059 virtual void b_read(vsl_b_istream& bfs) = 0; 00060 00061 //: Load description from a text stream 00062 static vcl_auto_ptr<clsfy_builder_base> new_builder( 00063 vcl_istream &as); 00064 00065 //: Initialise the parameters from a text stream. 00066 // Default case accepts no parameters. 00067 virtual void config(vcl_istream &as); 00068 00069 }; 00070 00071 //: Allows derived class to be loaded by base-class pointer 00072 void vsl_add_to_binary_loader(const clsfy_builder_base& b); 00073 00074 //: Binary file stream output operator for class reference 00075 void vsl_b_write(vsl_b_ostream& bfs, const clsfy_builder_base& b); 00076 00077 //: Binary file stream input operator for class reference 00078 void vsl_b_read(vsl_b_istream& bfs, clsfy_builder_base& b); 00079 00080 //: Stream output operator for class reference 00081 void vsl_print_summary(vcl_ostream& os,const clsfy_builder_base& b); 00082 00083 //: Stream output operator for class pointer 00084 void vsl_print_summary(vcl_ostream& os,const clsfy_builder_base* b); 00085 00086 //: Stream output operator for class reference 00087 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_base& b); 00088 00089 //: Stream output operator for class pointer 00090 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_base* b); 00091 00092 #endif // clsfy_builder_base_h_