00001 // This is mul/clsfy/clsfy_binary_threshold_1d.h 00002 #ifndef clsfy_binary_threshold_1d_h_ 00003 #define clsfy_binary_threshold_1d_h_ 00004 //: 00005 // \file 00006 // \brief Simplest possible 1D classifier: A single thresholding function 00007 // \author Tim Cootes 00008 00009 #include <clsfy/clsfy_classifier_1d.h> 00010 #include <vnl/vnl_vector.h> 00011 #include <vcl_iosfwd.h> 00012 00013 //: Simplest possible 1D classifier: A single thresholding function. 00014 // Returns class zero if s_*x<threshold_ 00015 00016 class clsfy_binary_threshold_1d : public clsfy_classifier_1d 00017 { 00018 protected: 00019 double s_; 00020 double threshold_; 00021 public: 00022 00023 //: Find the posterior probability of the input being in the positive class. 00024 // The result is outputs(0) 00025 virtual void class_probabilities(vcl_vector<double> &outputs, double input) const; 00026 00027 //: Classify the input vector. 00028 // Returns a number between 0 and nClasses-1 inclusive to represent the most likely class 00029 virtual unsigned classify(double input) const 00030 { if (s_*input<threshold_) return 0; else return 1; } 00031 00032 //: Log likelihood of being in the positive class/ 00033 // Class probability = 1 / (1+exp(-log_l)) 00034 virtual double log_l(double input) const; 00035 00036 //: Set the threshold and orientation. 00037 void set(double s, double t) 00038 { s_=s; threshold_=t; } 00039 00040 //: The number of possible output classes. 00041 // 1 indicates a binary classifier 00042 virtual unsigned n_classes() const { return 1;} 00043 00044 //: Return parameters defining classifier in a vector (format depends on classifier) 00045 virtual vnl_vector<double> params() const; 00046 00047 //: Set parameters defining classifier with a vector (format depends on classifier) 00048 virtual void set_params(const vnl_vector<double>& p); 00049 00050 //: Equality operator for 1d classifiers 00051 virtual bool operator==(const clsfy_classifier_1d& x) const; 00052 00053 //: Version number for I/O 00054 short version_no() const; 00055 00056 //: Name of the class 00057 virtual vcl_string is_a() const; 00058 00059 //: Name of the class 00060 virtual bool is_class(vcl_string const& s) const; 00061 00062 //: Print class to os 00063 virtual void print_summary(vcl_ostream& os) const; 00064 00065 //: Save class to a binary File Stream 00066 virtual void b_write(vsl_b_ostream& bfs) const; 00067 00068 //: Create a deep copy. 00069 // Client is responsible for deleting returned object. 00070 virtual clsfy_classifier_1d* clone() const 00071 { return new clsfy_binary_threshold_1d(*this); } 00072 00073 //: Load the class from a Binary File Stream 00074 virtual void b_read(vsl_b_istream& bfs); 00075 }; 00076 00077 #endif // clsfy_binary_threshold_1d_h_