1 // This is mul/clsfy/clsfy_binary_threshold_1d_builder.h 2 #ifndef clsfy_binary_threshold_1d_builder_h_ 3 #define clsfy_binary_threshold_1d_builder_h_ 4 //: 5 // \file 6 // \brief Describe a concrete classifier builder for scalar data 7 // \author Tim Cootes 8 9 #include <string> 10 #include <iostream> 11 #include <iosfwd> 12 #include <clsfy/clsfy_builder_1d.h> 13 #ifdef _MSC_VER 14 # include <vcl_msvc_warnings.h> 15 #endif 16 #include <vnl/vnl_vector.h> 17 #include <vbl/vbl_triple.h> 18 19 class clsfy_classifier_1d; 20 21 //: Base for classes to build clsfy_classifier_1d objects 22 class clsfy_binary_threshold_1d_builder : public clsfy_builder_1d 23 { 24 public: 25 26 // Dflt ctor 27 clsfy_binary_threshold_1d_builder(); 28 29 // Destructor 30 ~clsfy_binary_threshold_1d_builder() override; 31 32 //: Create empty model 33 clsfy_classifier_1d* new_classifier() const override; 34 35 36 //: Build a binary_threshold classifier 37 // Train classifier, returning weighted error 38 // Selects parameters of classifier which best separate examples from two classes, 39 // weighting examples appropriately when estimating the misclassification rate. 40 // Returns weighted sum of error, e.wts, where e_i =0 for correct classifications, 41 // e_i=1 for incorrect. 42 double build(clsfy_classifier_1d& classifier, 43 const vnl_vector<double>& egs, 44 const vnl_vector<double>& wts, 45 const std::vector<unsigned> &outputs) const override; 46 47 //: Build a binary_threshold classifier 48 // Train classifier, returning weighted error 49 // Selects parameters of classifier which best separate examples from two classes, 50 // weighting examples appropriately when estimating the misclassification rate. 51 // Returns weighted sum of error, e.wts, where e_i =0 for correct classifications, 52 // e_i=1 for incorrect. 53 double build(clsfy_classifier_1d& classifier, 54 vnl_vector<double>& egs0, 55 vnl_vector<double>& wts0, 56 vnl_vector<double>& egs1, 57 vnl_vector<double>& wts1) const override; 58 59 //: Train classifier, returning weighted error 60 // Selects parameters of classifier which best separate examples, 61 // weighting examples appropriately when estimating the misclassification rate. 62 // data[i] is a triple, {value,class_number,weight} 63 // Returns weighted sum of error. 64 // Note that input "data" must be sorted to use this routine 65 double build_from_sorted_data(clsfy_classifier_1d& classifier, 66 const vbl_triple<double,int,int> *data, 67 const vnl_vector<double>& wts) const override; 68 69 //: Name of the class 70 std::string is_a() const override; 71 72 //: Name of the class 73 bool is_class(std::string const& s) const override; 74 75 //: Version number for I/O 76 short version_no() const; 77 78 //: Create a copy on the heap and return base class pointer 79 clsfy_builder_1d* clone() const override; 80 81 //: Print class to os 82 void print_summary(std::ostream& os) const override; 83 84 //: Save class to binary file stream 85 void b_write(vsl_b_ostream& bfs) const override; 86 87 //: Load class from binary file stream 88 void b_read(vsl_b_istream& bfs) override; 89 }; 90 91 //: Binary file stream output operator for class reference 92 void vsl_b_write(vsl_b_ostream& bfs, const clsfy_binary_threshold_1d_builder& b); 93 94 //: Binary file stream input operator for class reference 95 void vsl_b_read(vsl_b_istream& bfs, clsfy_binary_threshold_1d_builder& b); 96 97 //: Stream output operator for class reference 98 std::ostream& operator<<(std::ostream& os,const clsfy_binary_threshold_1d_builder& b); 99 100 //: Stream output operator for class pointer 101 std::ostream& operator<<(std::ostream& os,const clsfy_binary_threshold_1d_builder* b); 102 103 #endif // clsfy_binary_threshold_1d_builder_h_ 104