contrib/mul/clsfy/clsfy_mean_square_1d.h
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_mean_square_1d.h
00002 #ifndef clsfy_mean_square_1d_h_
00003 #define clsfy_mean_square_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_mean_square_1d : public clsfy_classifier_1d
00017 {
00018  protected:
00019   double mean_;
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     { double k=(input-mean_);
00031       if (k*k<threshold_) return 1;
00032       else return 0; }
00033 
00034   //: Log likelihood of being in the positive class/
00035   // Class probability = 1 / (1+exp(-log_l))
00036   virtual double log_l(double input) const;
00037 
00038 #if 0
00039   //: Set the threshold and orientation.
00040   void set(double m, double t)
00041   { mean_=m; threshold_=t; }
00042 #endif // 0
00043 
00044   //: The number of possible output classes.
00045   // 1 indicates a binary classifier
00046   virtual unsigned  n_classes() const { return 1;}
00047 
00048   //: Return parameters defining classifier in a vector (format depends on classifier)
00049   virtual vnl_vector<double> params() const;
00050 
00051   //: Set parameters defining classifier with a vector (format depends on classifier)
00052   virtual void set_params(const vnl_vector<double>& p);
00053 
00054   //: Equality operator for 1d classifiers
00055   virtual bool operator==(const clsfy_classifier_1d& x) const;
00056 
00057   //: Version number for I/O
00058   short version_no() const;
00059 
00060   //: Name of the class
00061   virtual vcl_string is_a() const;
00062 
00063   //: Name of the class
00064   virtual bool is_class(vcl_string const& s) const;
00065 
00066   //: Print class to os
00067   virtual void print_summary(vcl_ostream& os) const;
00068 
00069   //: Save class to a binary File Stream
00070   virtual void b_write(vsl_b_ostream& bfs) const;
00071 
00072   //: Create a deep copy.
00073   // Client is responsible for deleting returned object.
00074   virtual clsfy_classifier_1d* clone() const
00075   { return new clsfy_mean_square_1d(*this); }
00076 
00077   //: Load the class from a Binary File Stream
00078   virtual void b_read(vsl_b_istream& bfs);
00079 };
00080 
00081 #endif // clsfy_mean_square_1d_h_