indii/ml/aux/DiracPdf.hpp

00001 #ifndef INDII_ML_AUX_DIRACPDF_HPP
00002 #define INDII_ML_AUX_DIRACPDF_HPP
00003 
00004 #include "Pdf.hpp"
00005 
00006 namespace indii {
00007   namespace ml {
00008     namespace aux {
00009 
00010 /**
00011  * Dirac \f$\delta\f$-function probability density.
00012  *
00013  * @author Lawrence Murray <lawrence@indii.org>
00014  * @version $Rev: 570 $
00015  * @date $Date: 2008-09-16 16:49:33 +0100 (Tue, 16 Sep 2008) $
00016  *
00017  * Supports serialization through the Boost.Serialization library.
00018  */
00019 class DiracPdf : public Pdf, public vector {
00020 public:
00021   /**
00022    * Default constructor.
00023    *
00024    * Initialises the Dirac with zero dimensions. This should generally
00025    * only be used when the object is to be restored from a
00026    * serialization. Indeed, there is no other way to resize the Dirac
00027    * to nonzero dimensionality except by subsequently restoring from a
00028    * serialization.
00029    */
00030   DiracPdf();
00031 
00032   /**
00033    * Constructor.
00034    *
00035    * @param x The expectation of the Dirac.
00036    */
00037   DiracPdf(const vector& x);
00038 
00039   /**
00040    * Construct Dirac given dimensionality. The expectation remains
00041    * uninitialised, and should be set with setExpectation().
00042    *
00043    * @param N \f$N\f$; number of dimensions of the Dirac.
00044    */
00045   DiracPdf(unsigned int N);
00046 
00047   /**
00048    * Destructor.
00049    */
00050   virtual ~DiracPdf();
00051 
00052   virtual void setDimensions(const unsigned int N,
00053       const bool preserve = false);
00054 
00055   /**
00056    * Get the expected value of the Dirac.
00057    *
00058    * @return \f$\mathbf{\mu}\f$; expected value of the Dirac.
00059    */
00060   virtual const vector& getExpectation() const;
00061 
00062   /**
00063    * (Don't) get the covariance of the Dirac.
00064    *
00065    * @return \f$\mathbf{\Sigma}\f$; covariance of the Dirac.
00066    */
00067   virtual const symmetric_matrix& getCovariance() const;
00068 
00069   virtual const vector& getExpectation();
00070 
00071   virtual const symmetric_matrix& getCovariance();
00072 
00073   virtual vector sample();
00074 
00075   virtual double densityAt(const vector& x);
00076 
00077 private:
00078   /**
00079    * Serialize, or restore from serialization.
00080    */
00081   template<class Archive>
00082   void serialize(Archive& ar, const unsigned int version);
00083 
00084   /*
00085    * Boost.Serialization requirements.
00086    */
00087   friend class boost::serialization::access;
00088 
00089 };
00090       
00091     }
00092   }
00093 }
00094 
00095 #include "boost/serialization/base_object.hpp"
00096 
00097 inline const indii::ml::aux::vector&
00098     indii::ml::aux::DiracPdf::getExpectation() const {
00099   return *this;
00100 }
00101 
00102 inline const indii::ml::aux::vector&
00103     indii::ml::aux::DiracPdf::getExpectation() {
00104   return *this;
00105 }
00106 
00107 inline indii::ml::aux::vector indii::ml::aux::DiracPdf::sample() {
00108   return *this;
00109 }
00110 
00111 inline double indii::ml::aux::DiracPdf::densityAt(const vector& x) {
00112   if (norm_inf(*this - x) == 0.0) {
00113     return std::numeric_limits<double>::infinity();
00114   } else {
00115     return 0.0;
00116   }
00117 }
00118 
00119 template<class Archive>
00120 void indii::ml::aux::DiracPdf::serialize(Archive& ar,
00121     const unsigned int version) {
00122   ar & boost::serialization::base_object<indii::ml::aux::Pdf>(*this);
00123   ar & boost::serialization::base_object<indii::ml::aux::vector>(*this);
00124 }
00125 
00126 #endif

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