pdf.h
Go to the documentation of this file.
1 // $Id$
2 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com>
3  /***************************************************************************
4  * This library is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU General Public *
6  * License as published by the Free Software Foundation; *
7  * version 2 of the License. *
8  * *
9  * As a special exception, you may use this file as part of a free *
10  * software library without restriction. Specifically, if other files *
11  * instantiate templates or use macros or inline functions from this *
12  * file, or you compile this file and link it with other files to *
13  * produce an executable, this file does not by itself cause the *
14  * resulting executable to be covered by the GNU General Public *
15  * License. This exception does not however invalidate any other *
16  * reasons why the executable file might be covered by the GNU General *
17  * Public License. *
18  * *
19  * This library is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22  * Lesser General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public *
25  * License along with this library; if not, write to the Free Software *
26  * Foundation, Inc., 59 Temple Place, *
27  * Suite 330, Boston, MA 02111-1307 USA *
28  * *
29  ***************************************************************************/
30 #ifndef PDF_H
31 #define PDF_H
32 
33 #include <vector>
34 #include <iostream>
35 #include "../wrappers/matrix/vector_wrapper.h"
36 #include "../wrappers/matrix/matrix_wrapper.h"
37 #include "../sample/sample.h"
38 #include "../bfl_err.h"
39 #include "../bfl_constants.h"
40 
41 
42 namespace BFL
43 {
44  using namespace std;
45 
46  // Defines for different sampling methods
47 #define DEFAULT 0 // Default sampling method, must be valid for every PDF!!
48 #define BOXMULLER 1
49 #define CHOLESKY 2
50 #define RIPLEY 3 // For efficient sampling from discrete/mcpdfs
51 
53  template <typename T> class Pdf
54  {
55 
56  public:
58 
60  Pdf(unsigned int dimension=0);
61 
62  // Default Copy Constructor will do the job
63 
65  virtual ~Pdf();
66 
68  virtual Pdf<T>* Clone() const = 0;
69 
71 
87  virtual bool SampleFrom (vector<Sample<T> >& list_samples,
88  const unsigned int num_samples,
89  int method = DEFAULT,
90  void * args = NULL) const;
91 
93 
103  virtual bool SampleFrom (Sample<T>& one_sample,
104  int method = DEFAULT,
105  void * args = NULL) const;
106 
108 
111  virtual Probability ProbabilityGet(const T& input) const;
112 
114 
116  unsigned int DimensionGet() const;
117 
119 
121  virtual void DimensionSet(unsigned int dim);
122 
124 
132  virtual T ExpectedValueGet() const;
133 
135 
141  virtual MatrixWrapper::SymmetricMatrix CovarianceGet() const;
142 
143  private:
145  unsigned int _dimension;
146 
147  };
148 
149 template<typename T>
150 Pdf<T>::Pdf(unsigned int dim)
151 {
152  assert((int)dim >= 0);
153 
154  _dimension = dim;
155 #ifdef __CONSTRUCTOR__
156  cout << "Pdf constructor" << endl;
157 #endif
158 }
159 
160 template<typename T>
161 Pdf<T>::~Pdf()
162 {
163 #ifdef __DESTRUCTOR__
164  cout << "Pdf destructor" << endl;
165 #endif
166 }
167 
168 template<typename T> inline unsigned int
169 Pdf<T>::DimensionGet () const
170 {
171  return _dimension;
172 }
173 
174 template<typename T> void
175 Pdf<T>::DimensionSet ( unsigned int dim )
176 {
177  assert((int)dim >= 0);
178  _dimension = dim;
179 }
180 
181 template<typename T> bool
182 Pdf<T>::SampleFrom (vector<Sample<T> >& list_samples,
183  const unsigned int num_samples,
184  int method,
185  void * args) const
186 {
187  list_samples.resize(num_samples);
188  typename vector<Sample<T> >::iterator sample_it;
189  for (sample_it = list_samples.begin(); sample_it != list_samples.end() ; sample_it++)
190  if (!this->SampleFrom(*sample_it, method,args))
191  return false;
192 
193  return true;
194 }
195 
196 template<typename T> bool
197 Pdf<T>::SampleFrom (Sample<T>& one_sample,
198  int method,
199  void * args) const
200 {
201  cerr << "Error Pdf<T>: The SampleFrom function was called, but you didn't implement it!\n";
202  exit(-BFL_ERRMISUSE);
203  return false;
204 }
205 
206 template<typename T> Probability
207 Pdf<T>::ProbabilityGet (const T& input) const
208 {
209  cerr << "Error Pdf<T>: The ProbabilityGet function was called, but you didn't implement it!\n";
210  exit(-BFL_ERRMISUSE);
211  return 1;
212 }
213 
214 template<typename T> T
216 {
217  cerr << "Error Pdf<T>: The ExpectedValueGet function was called, but you didn't implement it!\n";
218  exit(-BFL_ERRMISUSE);
219  T t;
220  return t;
221 }
222 
223 
224 template<typename T> MatrixWrapper::SymmetricMatrix
225 Pdf<T>::CovarianceGet () const
226 {
227  cerr << "Error Pdf<T>: The CovarianceGet function was called, but you didn't implement it!\n";
228  exit(-BFL_ERRMISUSE);
229  MatrixWrapper::SymmetricMatrix m;
230  return m;
231 }
232 
233 
234 
235 } // End namespace
236 #endif
virtual void DimensionSet(unsigned int dim)
Set the dimension of the argument.
Class PDF: Virtual Base class representing Probability Density Functions.
Definition: pdf.h:53
virtual MatrixWrapper::SymmetricMatrix CovarianceGet() const
Get the Covariance Matrix E[(x - E[x])^2] of the Analytic pdf.
virtual Probability ProbabilityGet(const T &input) const
Get the probability of a certain argument.
unsigned int _dimension
Dimension of the argument x of P(x | ...).
Definition: pdf.h:145
Pdf(unsigned int dimension=0)
Constructor.
unsigned int DimensionGet() const
Get the dimension of the argument.
virtual bool SampleFrom(vector< Sample< T > > &list_samples, const unsigned int num_samples, int method=DEFAULT, void *args=NULL) const
Draw multiple samples from the Pdf (overloaded)
virtual T ExpectedValueGet() const
Get the expected value E[x] of the pdf.
#define BFL_ERRMISUSE
#define DEFAULT
Definition: pdf.h:47
virtual ~Pdf()
Destructor.
Class representing a probability (a double between 0 and 1)
Definition: bfl_constants.h:39


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 Mon Jun 10 2019 12:47:59