contrib/mul/clsfy/clsfy_builder_base.h
Go to the documentation of this file.
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 <vsl/vsl_binary_io.h>
00015 #include <vcl_vector.h>
00016 #include <vcl_string.h>
00017 #include <vcl_memory.h>
00018 #include <mbl/mbl_data_wrapper.h>
00019 #include <vnl/vnl_vector.h>
00020 
00021 class clsfy_classifier_base;
00022 
00023 //: Base for classes to build clsfy_classifier_base objects
00024 class clsfy_builder_base
00025 {
00026  public:
00027   // Destructor
00028   virtual ~clsfy_builder_base() {}
00029 
00030   //: Create empty model
00031   virtual clsfy_classifier_base* new_classifier() const = 0;
00032 
00033   //: Build model from data
00034   // Return the mean error over the training set.
00035   // For many classifiers, you may use nClasses==1 to
00036   // indicate a binary classifier
00037   virtual double build(clsfy_classifier_base& model,
00038                        mbl_data_wrapper<vnl_vector<double> >& inputs,
00039                        unsigned nClasses,
00040                        const vcl_vector<unsigned> &outputs) const = 0;
00041 
00042   //: Name of the class
00043   virtual vcl_string is_a() const;
00044 
00045   //: Name of the class
00046   virtual bool is_class(vcl_string const& s) const;
00047 
00048   //: Create a copy on the heap and return base class pointer
00049   virtual clsfy_builder_base* clone() const = 0;
00050 
00051   //: Print class to os
00052   virtual void print_summary(vcl_ostream& os) const = 0;
00053 
00054   //: Save class to binary file stream
00055   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00056 
00057   //: Load class from binary file stream
00058   virtual void b_read(vsl_b_istream& bfs) = 0;
00059 
00060   //: Load description from a text stream
00061   static vcl_auto_ptr<clsfy_builder_base> new_builder(
00062     vcl_istream &as);
00063 
00064   //: Initialise the parameters from a text stream.
00065   // Default case accepts no parameters.
00066   virtual void config(vcl_istream &as);
00067 
00068 };
00069 
00070 //: Allows derived class to be loaded by base-class pointer
00071 void vsl_add_to_binary_loader(const clsfy_builder_base& b);
00072 
00073 //: Binary file stream output operator for class reference
00074 void vsl_b_write(vsl_b_ostream& bfs, const clsfy_builder_base& b);
00075 
00076 //: Binary file stream input operator for class reference
00077 void vsl_b_read(vsl_b_istream& bfs, clsfy_builder_base& b);
00078 
00079 //: Stream output operator for class reference
00080 void vsl_print_summary(vcl_ostream& os,const clsfy_builder_base& b);
00081 
00082 //: Stream output operator for class pointer
00083 void vsl_print_summary(vcl_ostream& os,const clsfy_builder_base* b);
00084 
00085 //: Stream output operator for class reference
00086 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_base& b);
00087 
00088 //: Stream output operator for class pointer
00089 vcl_ostream& operator<<(vcl_ostream& os,const clsfy_builder_base* b);
00090 
00091 #endif // clsfy_builder_base_h_