indii/ml/aux/UniformPdf.hpp

00001 #ifndef INDII_ML_AUX_UNIFORMTREEPDF_HPP
00002 #define INDII_ML_AUX_UNIFORMTREEPDF_HPP
00003 
00004 #include "Pdf.hpp"
00005 
00006 namespace indii {
00007   namespace ml {
00008     namespace aux {
00009 /**
00010  * Uniform distribution over a hyper-rectangle.
00011  *
00012  * @author Lawrence Murray <lawrence@indii.org>
00013  * @version $Rev: 538 $
00014  * @date $Date: 2008-08-31 14:41:10 +0100 (Sun, 31 Aug 2008) $
00015  * 
00016  * @section UniformPdf_serialization Serialization
00017  *
00018  * This class supports serialization through the Boost.Serialization
00019  * library.
00020  */
00021 class UniformPdf : public Pdf {
00022 public:
00023   /**
00024    * Default constructor.
00025    *
00026    * Initialises the distribution with zero dimensions. This should
00027    * generally only be used when the object is to be restored from a
00028    * serialization.
00029    */
00030   UniformPdf();
00031 
00032   /**
00033    * Constructor.
00034    *
00035    * @param lower Lower corner of the hyper-rectangle under the
00036    * distribution.
00037    * @param upper Upper corner of the hyper-rectangle under the
00038    * distribution.
00039    */
00040   UniformPdf(const vector& lower, const vector& upper);
00041 
00042   /**
00043    * Destructor.
00044    */
00045   ~UniformPdf();
00046 
00047   /**
00048    * Assignment operator. Both sides must have the same dimensionality.
00049    */
00050   virtual UniformPdf& operator=(const UniformPdf& o);
00051 
00052   virtual void setDimensions(const unsigned int N,
00053       const bool preserve = false);
00054   
00055   virtual const vector& getExpectation();
00056 
00057   virtual const symmetric_matrix& getCovariance();
00058 
00059   virtual vector sample();
00060 
00061   virtual double densityAt(const vector& x);
00062 
00063 private:
00064   /**
00065    * Density of the distribution.
00066    */
00067   double p;
00068 
00069   /**
00070    * Lower corner of the hyper-rectangle under the distribution.
00071    */
00072   vector lower;
00073   
00074   /**
00075    * Upper corner of the hyper-rectangle under the distribution.
00076    */
00077   vector upper;
00078 
00079   /**
00080    * \f$\mathbf{\mu}\f$; mean of the distribution.
00081    */
00082   vector mu;
00083 
00084   /**
00085    * \f$\Sigma\f$; covariance of the distribution.
00086    */
00087   symmetric_matrix sigma;
00088 
00089   /**
00090    * Has \f$\mathbf{\mu}\f$ been calculated?
00091    */
00092   bool haveMu;
00093   
00094   /**
00095    * Has \f$\Sigma\f$ been calculated?
00096    */
00097   bool haveSigma;
00098 
00099   /**
00100    * Calculate \f$\mathbf{\mu}\f$.
00101    */
00102   void calculateExpectation();
00103   
00104   /**
00105    * Calculate \f$\Sigma\f$.
00106    */
00107   void calculateCovariance();
00108 
00109   /**
00110    * Calculate density over the hyper-rectangle defined by lower and upper.
00111    */
00112   void calculateDensity();
00113 
00114   /**
00115    * Serialize.
00116    */
00117   template<class Archive>
00118   void save(Archive& ar, const unsigned int version) const;
00119 
00120   /**
00121    * Restore from serialization.
00122    */
00123   template<class Archive>
00124   void load(Archive& ar, const unsigned int version);
00125 
00126   /*
00127    * Boost.Serialization requirements.
00128    */
00129   BOOST_SERIALIZATION_SPLIT_MEMBER()
00130   friend class boost::serialization::access;
00131 
00132 };
00133 
00134     }
00135   }
00136 }
00137 
00138 template<class Archive>
00139 void indii::ml::aux::UniformPdf::save(Archive& ar,
00140     const unsigned int version) const {
00141   ar & boost::serialization::base_object<Pdf>(*this);
00142   ar & p;
00143   ar & lower;
00144   ar & upper;
00145 }
00146 
00147 template<class Archive>
00148 void indii::ml::aux::UniformPdf::load(Archive& ar,
00149     const unsigned int version) {
00150   ar & boost::serialization::base_object<Pdf>(*this);
00151   ar & p;
00152   ar & lower;
00153   ar & upper;
00154   
00155   haveMu = false;
00156   haveSigma = false;
00157   mu.resize(N);
00158   sigma.resize(N);
00159 }
00160 
00161 #endif
00162 

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