pdf.h
Go to the documentation of this file.
00001 // $Id: pdf.h 29890 2009-02-02 10:22:01Z tdelaet $
00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
00003  /***************************************************************************
00004  *   This library is free software; you can redistribute it and/or         *
00005  *   modify it under the terms of the GNU General Public                   *
00006  *   License as published by the Free Software Foundation;                 *
00007  *   version 2 of the License.                                             *
00008  *                                                                         *
00009  *   As a special exception, you may use this file as part of a free       *
00010  *   software library without restriction.  Specifically, if other files   *
00011  *   instantiate templates or use macros or inline functions from this     *
00012  *   file, or you compile this file and link it with other files to        *
00013  *   produce an executable, this file does not by itself cause the         *
00014  *   resulting executable to be covered by the GNU General Public          *
00015  *   License.  This exception does not however invalidate any other        *
00016  *   reasons why the executable file might be covered by the GNU General   *
00017  *   Public License.                                                       *
00018  *                                                                         *
00019  *   This library is distributed in the hope that it will be useful,       *
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00022  *   Lesser General Public License for more details.                       *
00023  *                                                                         *
00024  *   You should have received a copy of the GNU General Public             *
00025  *   License along with this library; if not, write to the Free Software   *
00026  *   Foundation, Inc., 59 Temple Place,                                    *
00027  *   Suite 330, Boston, MA  02111-1307  USA                                *
00028  *                                                                         *
00029  ***************************************************************************/
00030 #ifndef PDF_H
00031 #define PDF_H
00032 
00033 #include <vector>
00034 #include <iostream>
00035 #include "../wrappers/matrix/vector_wrapper.h"
00036 #include "../wrappers/matrix/matrix_wrapper.h"
00037 #include "../sample/sample.h"
00038 #include "../bfl_err.h"
00039 #include "../bfl_constants.h"
00040 
00041 
00042 namespace BFL
00043 {
00044   using namespace std;
00045 
00046   // Defines for different sampling methods
00047 #define DEFAULT 0 // Default sampling method, must be valid for every PDF!!
00048 #define BOXMULLER 1
00049 #define CHOLESKY 2
00050 #define RIPLEY 3 // For efficient sampling from discrete/mcpdfs
00051 
00053   template <typename T> class Pdf
00054     {
00055 
00056     public:
00058 
00060       Pdf(unsigned int dimension=0);
00061 
00062       // Default Copy Constructor will do the job
00063 
00065       virtual ~Pdf();
00066 
00068       virtual Pdf<T>* Clone() const = 0;
00069 
00071 
00087       virtual bool SampleFrom (vector<Sample<T> >& list_samples,
00088                                const unsigned int num_samples,
00089                                int method = DEFAULT,
00090                                void * args = NULL) const;
00091 
00093 
00103       virtual bool  SampleFrom (Sample<T>& one_sample,
00104                                 int method = DEFAULT,
00105                                 void * args = NULL) const;
00106 
00108 
00111       virtual Probability ProbabilityGet(const T& input) const;
00112 
00114 
00116       unsigned int DimensionGet() const;
00117 
00119 
00121       virtual void DimensionSet(unsigned int dim);
00122 
00124 
00132       virtual T ExpectedValueGet() const;
00133 
00135 
00141       virtual MatrixWrapper::SymmetricMatrix CovarianceGet() const;
00142 
00143     private:
00145       unsigned int _dimension;
00146 
00147     };
00148 
00149 template<typename T>
00150 Pdf<T>::Pdf(unsigned int dim)
00151 {
00152   assert((int)dim >= 0);
00153 
00154   _dimension = dim;
00155 #ifdef __CONSTRUCTOR__
00156   cout << "Pdf constructor" << endl;
00157 #endif
00158 }
00159 
00160 template<typename T>
00161 Pdf<T>::~Pdf()
00162 {
00163 #ifdef __DESTRUCTOR__
00164   cout << "Pdf destructor" << endl;
00165 #endif
00166 }
00167 
00168 template<typename T> inline unsigned int
00169 Pdf<T>::DimensionGet () const
00170 {
00171   return _dimension;
00172 }
00173 
00174 template<typename T> void
00175 Pdf<T>::DimensionSet ( unsigned int dim )
00176 {
00177   assert((int)dim >= 0);
00178   _dimension = dim;
00179 }
00180 
00181 template<typename T> bool
00182 Pdf<T>::SampleFrom (vector<Sample<T> >& list_samples,
00183                     const unsigned int num_samples,
00184                     int method,
00185                     void * args) const
00186 {
00187   list_samples.resize(num_samples);
00188   typename vector<Sample<T> >::iterator sample_it;
00189   for (sample_it = list_samples.begin(); sample_it != list_samples.end() ; sample_it++)
00190     if (!this->SampleFrom(*sample_it, method,args))
00191       return false;
00192 
00193   return true;
00194 }
00195 
00196 template<typename T> bool
00197 Pdf<T>::SampleFrom (Sample<T>& one_sample,
00198                     int method,
00199                     void * args) const
00200 {
00201   cerr << "Error Pdf<T>: The SampleFrom function was called, but you didn't implement it!\n";
00202   exit(-BFL_ERRMISUSE);
00203   return false;
00204 }
00205 
00206 template<typename T> Probability
00207 Pdf<T>::ProbabilityGet (const T& input) const
00208 {
00209   cerr << "Error Pdf<T>: The ProbabilityGet function was called, but you didn't implement it!\n";
00210   exit(-BFL_ERRMISUSE);
00211   return 1;
00212 }
00213 
00214 template<typename T>  T
00215 Pdf<T>::ExpectedValueGet () const
00216 {
00217   cerr << "Error Pdf<T>: The ExpectedValueGet function was called, but you didn't implement it!\n";
00218   exit(-BFL_ERRMISUSE);
00219   T t;
00220   return t;
00221 }
00222 
00223 
00224 template<typename T> MatrixWrapper::SymmetricMatrix
00225 Pdf<T>::CovarianceGet () const
00226 {
00227   cerr << "Error Pdf<T>: The CovarianceGet function was called, but you didn't implement it!\n";
00228   exit(-BFL_ERRMISUSE);
00229   MatrixWrapper::SymmetricMatrix m;
00230   return m;
00231 }
00232 
00233 
00234 
00235 } // End namespace
00236 #endif


bfl
Author(s): Klaas Gadeyne, Wim Meeussen, Tinne Delaet and many others. See web page for a full contributor list. ROS package maintained by Wim Meeussen.
autogenerated on Sun Oct 5 2014 22:29:53