indii/ml/aux/Pdf.hpp

00001 #ifndef INDII_ML_AUX_PDF_HPP
00002 #define INDII_ML_AUX_PDF_HPP
00003 
00004 #include "vector.hpp"
00005 #include "matrix.hpp"
00006 
00007 namespace indii {
00008   namespace ml {
00009     namespace aux {
00010 
00011 /**
00012  * Abstract probability distribution.
00013  *
00014  * @author Lawrence Murray <lawrence@indii.org>
00015  * @version $Rev: 538 $
00016  * @date $Date: 2008-08-31 14:41:10 +0100 (Sun, 31 Aug 2008) $
00017  */
00018 class Pdf {
00019 public:
00020   /**
00021    * Default constructor.
00022    *
00023    * Initialises the density with zero dimensions. This should
00024    * generally only be used when the object is to be restored from a
00025    * serialization.
00026    */
00027   Pdf();
00028 
00029   /**
00030    * Constructor.
00031    *
00032    * @param N \f$N\f$; number of dimensions of the density.
00033    */
00034   Pdf(const unsigned int N);
00035 
00036   /**
00037    * Destructor.
00038    */
00039   virtual ~Pdf();
00040 
00041   /**
00042    * Get the dimensionality of the distribution.
00043    *
00044    * @return Dimensionality of the distribution.
00045    */
00046   unsigned int getDimensions() const;
00047 
00048   /**
00049    * Set the dimensionality of the distribution.
00050    *
00051    * @param N Dimensionality of the distribution.
00052    * @param preserve True to preserve the current sufficient
00053    * statistics of the distribution in the lower dimensional space,
00054    * false if these may be discarded.
00055    */
00056   virtual void setDimensions(const unsigned int N,
00057       const bool preserve = false) = 0;
00058 
00059   /**
00060    * Get the expected value of the distribution.
00061    *
00062    * @return \f$\mathbf{\mu}\f$; expected value of the distribution.
00063    */
00064   virtual const vector& getExpectation() = 0;
00065 
00066   /**
00067    * Get the covariance of the distribution.
00068    *
00069    * @return \f$\Sigma\f$; covariance of the distribution.
00070    */
00071   virtual const symmetric_matrix& getCovariance() = 0;
00072 
00073   /**
00074    * Sample from the distribution.
00075    *
00076    * @return A sample from the distribution.
00077    */
00078   virtual vector sample() = 0;
00079 
00080   /**
00081    * Calculate the density at a given point.
00082    *
00083    * @param x \f$\mathbf{x}\f$; point at which to evaluate the
00084    * density.
00085    *
00086    * @return \f$p(\mathbf{x})\f$; the density at \f$\mathbf{x}\f$.
00087    */
00088   virtual double densityAt(const vector& x) = 0;
00089 
00090 protected:
00091   /**
00092    * \f$N\f$; number of dimensions.
00093    */
00094   unsigned int N;
00095 
00096 private:
00097   /**
00098    * Serialize, or restore from serialization.
00099    */
00100   template<class Archive>
00101   void serialize(Archive& ar, const unsigned int version);
00102 
00103   /*
00104    * Boost.Serialization requirements.
00105    */
00106   friend class boost::serialization::access;
00107 
00108 };
00109 
00110     }
00111   }
00112 }
00113 
00114 inline unsigned int indii::ml::aux::Pdf::getDimensions() const {
00115   return N;
00116 }
00117 
00118 template<class Archive>
00119 void indii::ml::aux::Pdf::serialize(Archive& ar, const unsigned int version) {
00120   ar & N;
00121 }
00122 
00123 #endif
00124 

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