contrib/mul/clsfy/clsfy_binary_threshold_1d_gini_builder.h
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_binary_threshold_1d_gini_builder.h
00002 #ifndef clsfy_binary_threshold_1d_gini_builder_h_
00003 #define clsfy_binary_threshold_1d_gini_builder_h_
00004 //:
00005 // \file
00006 // \brief Builder  of 1d threshold using gini index
00007 // \author Martin Roberts
00008 
00009 #include <clsfy/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 #include <clsfy/clsfy_binary_threshold_1d_builder.h>
00016 // Note this is used by clsfy_binary_tree_builder
00017 // Derived from clsfy_binary_threshold_1d_builder but uses a slightly different
00018 // interface to do the gini index optimisation, as tis returns the reduction
00019 // in the gini impurity (not classification error).
00020 
00021 class clsfy_binary_threshold_1d_gini_builder : public clsfy_binary_threshold_1d_builder
00022 {
00023  public:
00024 
00025   // Dflt ctor
00026   clsfy_binary_threshold_1d_gini_builder();
00027 
00028   // Destructor
00029   virtual ~clsfy_binary_threshold_1d_gini_builder();
00030 
00031   //: Create empty model
00032   virtual clsfy_classifier_1d* new_classifier() const;
00033 
00034 
00035   //: Build a binary_threshold classifier
00036   //  Train classifier
00037   //  Selects parameters of classifier which best separate examples from two classes,
00038   // Uses the gini impurity index
00039   // Note it returns the -reduction in Gini impurity produced by the split
00040   // Not the misclassification rate
00041   // (i.e. but minimise as per error rate)
00042   virtual double build_gini(clsfy_classifier_1d& classifier,
00043                             const vnl_vector<double>& inputs,
00044                             const vcl_vector<unsigned> &outputs) const;
00045 
00046  
00047   //  Note that input "data" must be sorted to use this routine
00048   virtual double build_gini_from_sorted_data(clsfy_classifier_1d& classifier,
00049                                              const vcl_vector<vbl_triple<double,int,int> >& data) const;
00050 
00051   //: Name of the class
00052   virtual vcl_string is_a() const;
00053 
00054   //: Name of the class
00055   virtual bool is_class(vcl_string const& s) const;
00056 
00057   //: Version number for I/O
00058   short version_no() const;
00059 
00060   //: Create a copy on the heap and return base class pointer
00061   virtual clsfy_builder_1d* clone() const;
00062 
00063   //: Print class to os
00064   virtual void print_summary(vcl_ostream& os) const;
00065 
00066   //: Save class to binary file stream
00067   virtual void b_write(vsl_b_ostream& bfs) const;
00068 
00069   //: Load class from binary file stream
00070   virtual void b_read(vsl_b_istream& bfs);
00071 };
00072 
00073 
00074 #endif // clsfy_binary_threshold_1d_gini_builder_h_