indii/ml/aux/Kernel.hpp

00001 #ifndef INDII_ML_AUX_KERNEL_HPP
00002 #define INDII_ML_AUX_KERNEL_HPP
00003 
00004 #include "boost/serialization/serialization.hpp"
00005 
00006 namespace indii {
00007   namespace ml {
00008     namespace aux {
00009 /**
00010  * %Kernel for density estimation.
00011  *
00012  * @author Lawrence Murray <lawrence@indii.org>
00013  * @version $Rev: 477 $
00014  * @date $Date: 2008-07-24 23:39:18 +0100 (Thu, 24 Jul 2008) $
00015  *
00016  * @section Serialization
00017  *
00018  * This class supports serialization through the Boost.Serialization
00019  * library.
00020  */
00021 class Kernel {
00022 public:
00023   /**
00024    * Default constructor.
00025    *
00026    * This should generally only be used when the object is to be restored
00027    * from a serialization.
00028    */
00029   Kernel();
00030 
00031   /**
00032    * Constructor.
00033    *
00034    * @param h \f$h\f$; the scaling parameter (bandwidth).
00035    */
00036   Kernel(const double h);
00037 
00038   /**
00039    * Destructor.
00040    */
00041   virtual ~Kernel() = 0;
00042 
00043   /**
00044    * Get kernel bandwidth.
00045    *
00046    * @return Kernel bandwidth.
00047    */
00048   double getBandwidth() const;
00049 
00050   /**
00051    * Comparison operator for sorting etc.
00052    *
00053    * @param o Object to which to compare.
00054    *
00055    * @return True if the bandwidth of @p this is less than the bandwidth of
00056    * @p o.
00057    */
00058   bool operator<(const Kernel& o) const;
00059 
00060   /**
00061    * Evaluate the kernel.
00062    *
00063    * @param x Point at which to evaluate the kernel.
00064    *
00065    * @return Density of the kernel at the given point.
00066    */
00067   virtual double operator()(const double x) const = 0;
00068   
00069   virtual double sample() const = 0;
00070 
00071 private:
00072   /**
00073    * \f$h\f$; the scaling parameter (bandwidth).
00074    */
00075   double h;
00076 
00077   /**
00078    * Serialize.
00079    */
00080   template<class Archive>
00081   void serialize(Archive& ar, const unsigned int version);
00082 
00083   /*
00084    * Boost.Serialization requirements.
00085    */
00086   friend class boost::serialization::access;
00087 
00088 };
00089 
00090     }
00091   }
00092 }
00093 
00094 inline double indii::ml::aux::Kernel::getBandwidth() const {
00095   return h;
00096 }
00097 
00098 inline bool indii::ml::aux::Kernel::operator<(
00099     const indii::ml::aux::Kernel& o) const {
00100   return this->getBandwidth() < o.getBandwidth();
00101 }
00102 
00103 template<class Archive>
00104 void indii::ml::aux::Kernel::serialize(Archive& ar,
00105     const unsigned int version) {  
00106   ar & h;
00107 }
00108 
00109 #endif
00110 

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3