contrib/mul/mfpf/mfpf_log_lin_class_cost.h
Go to the documentation of this file.
00001 #ifndef mfpf_log_lin_class_cost_h_
00002 #define mfpf_log_lin_class_cost_h_
00003 //:
00004 // \file
00005 // \brief Computes log prob based on output of a linear classifier
00006 // \author Tim Cootes
00007 
00008 #include <mfpf/mfpf_vec_cost.h>
00009 #include <vcl_iosfwd.h>
00010 
00011 //: Computes log prob based on output of a linear classifier
00012 //  Linear classifier gives output z = w.x - bias
00013 //  This returns -log(minp + (1-minp)/(1+exp(-z)))
00014 //  minp defines the minimum prob output by classifier,
00015 //  which should be non-zero to avoid danger of log(0)
00016 class mfpf_log_lin_class_cost : public mfpf_vec_cost
00017 {
00018  private:
00019   //: Classifier weights
00020   vnl_vector<double> wts_;
00021 
00022   //: Classifier bias
00023   double bias_;
00024 
00025   //: Minimum probability allowed in response
00026   double min_p_;
00027  public:
00028 
00029   //: Dflt ctor
00030   mfpf_log_lin_class_cost();
00031 
00032   //: Destructor
00033   virtual ~mfpf_log_lin_class_cost();
00034 
00035   //: Define weights, bias and minp
00036   void set(const vnl_vector<double>& wts, double bias, double min_p=1e-6);
00037 
00038   //: Weights to apply to each element in sum
00039   const vnl_vector<double>& wts() const { return wts_; }
00040 
00041   //: Returns -log(minp + (1-minp)/(1+exp(-(x.wts-bias)))
00042   virtual double evaluate(const vnl_vector<double>& x);
00043 
00044   //: Return the weights
00045   virtual void get_average(vnl_vector<double>& v) const;
00046 
00047   //: Version number for I/O
00048   short version_no() const;
00049 
00050   //: Name of the class
00051   virtual vcl_string is_a() const;
00052 
00053   //: Create a copy on the heap and return base class pointer
00054   virtual mfpf_vec_cost* clone() const;
00055 
00056   //: Print class to os
00057   virtual void print_summary(vcl_ostream& os) const;
00058 
00059   //: Save class to binary file stream
00060   virtual void b_write(vsl_b_ostream& bfs) const;
00061 
00062   //: Load class from binary file stream
00063   virtual void b_read(vsl_b_istream& bfs);
00064 };
00065 
00066 #endif