contrib/mul/clsfy/clsfy_parzen_builder.h
Go to the documentation of this file.
00001 // This is mul/clsfy/clsfy_parzen_builder.h
00002 // Copyright: (C) 2001 British Telecommunications plc
00003 #ifndef clsfy_parzen_builder_h_
00004 #define clsfy_parzen_builder_h_
00005 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00006 #pragma interface
00007 #endif
00008 //:
00009 // \file
00010 // \brief Describe a Parzen window classifier builder
00011 // \author Ian Scott
00012 // \date 2001-10-07
00013 
00014 #include <clsfy/clsfy_builder_base.h>
00015 #include <vcl_vector.h>
00016 #include <vcl_string.h>
00017 #include <vcl_iosfwd.h>
00018 #include <mbl/mbl_data_wrapper.h>
00019 #include <vnl/vnl_vector.h>
00020 
00021 
00022 //: Builds clsfy_rbf_parzen classifiers.
00023 // This class doesn't do any calculation, it is easy to create a
00024 // Parzen window classifier directly - but it allows for consistent swappable
00025 // classifiers.
00026 class clsfy_parzen_builder : public clsfy_builder_base
00027 {
00028   //: The width of the RBF window function.  Default value is 1.0.
00029   double sigma_;
00030 
00031   //: The power, p, in the window function.  Default value is 2.0.
00032   double power_;
00033 
00034  public:
00035   // Dflt ctor
00036   clsfy_parzen_builder();
00037 
00038   //: Create empty model
00039   // Caller is responsible for deletion
00040   virtual clsfy_classifier_base* new_classifier() const;
00041 
00042   //: Build classifier from data
00043   // return the mean error over the training set.
00044   virtual double build(clsfy_classifier_base& model,
00045                        mbl_data_wrapper<vnl_vector<double> >& inputs,
00046                        unsigned nClasses,
00047                        const vcl_vector<unsigned> &outputs) const;
00048 
00049   //: Name of the class
00050   virtual vcl_string is_a() const;
00051 
00052   //: Name of the class
00053   virtual bool is_class(vcl_string const& s) const;
00054 
00055   //: IO Version number
00056   short version_no() const;
00057 
00058   //: Create a copy on the heap and return base class pointer
00059   virtual clsfy_builder_base* clone() const;
00060 
00061   //: Print class to os
00062   virtual void print_summary(vcl_ostream& os) const;
00063 
00064   //: Save class to binary file stream
00065   virtual void b_write(vsl_b_ostream& bfs) const;
00066 
00067   //: Load class from binary file stream
00068   virtual void b_read(vsl_b_istream& bfs);
00069 
00070   //: The 1st standard deviation width of the RBF window.
00071   // The default value is 1.
00072   double rbf_width() const { return sigma_;}
00073 
00074   //: Set the 1st standard deviation width of the RBF window.
00075   // The default value is 1.
00076   void set_rbf_width(double sigma);
00077 
00078   //: The value p in the window function $exp(-1/(2*sigma^p) * |x-y|^p)$.
00079   // The value p affects the kurtosis, or peakyness of the window. Towards 0 gives a more peaked central spike, and longer tail.
00080   // Toward +inf gives a broader peak, and shorter tail.
00081   // The default value is 2, giving a Gaussian distribution.
00082   double power() const { return power_;}
00083 
00084   //: The value p in the window function $exp(-1/(2*sigma^p) * |x-y|^p)$.
00085   // The value p affects the kurtosis, or peakyness of the window. Towards 0 gives a more peaked central spike, and longer tail.
00086   // Toward +inf gives a broader peak, and shorter tail.
00087   // The default value is 2, giving a Gaussian distribution.
00088   void set_power(double p);
00089 
00090   //: Initialise the parameters from a text stream.
00091   void config(vcl_istream &as);
00092 };
00093 
00094 
00095 #endif // clsfy_parzen_builder_h_