PDFDirichlet.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file PDFDirichlet.cpp
  3. * @brief Normal Distribution / Gaussian PDF
  4. * @author Erik Rodner
  5. * @date 01/29/2008
  6. */
  7. #include <iostream>
  8. #include "vislearning/math/pdf/PDFDirichlet.h"
  9. #include "vislearning/math/pdf/gslRandomNumberGenerator.h"
  10. using namespace OBJREC;
  11. using namespace std;
  12. // refactor-nice.pl: check this substitution
  13. // old: using namespace ice;
  14. using namespace NICE;
  15. PDFDirichlet::PDFDirichlet( double _alpha, int dimension ) : alpha(dimension)
  16. {
  17. for ( int i = 0 ; i < dimension ; i++ )
  18. alpha[i] = _alpha / dimension;
  19. }
  20. // refactor-nice.pl: check this substitution
  21. // old: PDFDirichlet::PDFDirichlet ( const Vector & _alpha ) : alpha(_alpha)
  22. PDFDirichlet::PDFDirichlet ( const NICE::Vector & _alpha ) : alpha(_alpha)
  23. {
  24. }
  25. PDFDirichlet::~PDFDirichlet()
  26. {
  27. }
  28. // refactor-nice.pl: check this substitution
  29. // old: double PDFDirichlet::getNLogDensity ( const Vector & x ) const
  30. double PDFDirichlet::getNLogDensity ( const NICE::Vector & x ) const
  31. {
  32. #ifdef NICE_USELIB_GSL
  33. return gsl_ran_dirichlet_lnpdf ( alpha.size(), alpha.getDataPointerConst(), x.getDataPointerConst() );
  34. #else
  35. #warning "PDFDirichlet::getNLogDensity: this function needs the GNU Scientific Library"
  36. fprintf (stderr, "PDFDirichlet::getNLogDensity: this function needs the GNU Scientific Library\n");
  37. exit(-1);
  38. return 0.0;
  39. #endif
  40. }
  41. // refactor-nice.pl: check this substitution
  42. // old: double PDFDirichlet::getProb ( const Vector & x ) const
  43. double PDFDirichlet::getProb ( const NICE::Vector & x ) const
  44. {
  45. #ifdef NICE_USELIB_GSL
  46. return gsl_ran_dirichlet_pdf ( alpha.size(), alpha.getDataPointerConst(), x.getDataPointerConst() );
  47. #else
  48. #warning "PDFDirichlet::getProb: this function needs the GNU Scientific Library"
  49. fprintf (stderr, "PDFDirichlet::getProb: this function needs the GNU Scientific Library\n");
  50. exit(-1);
  51. return 0.0;
  52. #endif
  53. }
  54. int PDFDirichlet::getDimension () const
  55. {
  56. return alpha.size();
  57. }
  58. void PDFDirichlet::sample ( VVector & samples, int count ) const
  59. {
  60. #ifdef NICE_USELIB_GSL
  61. initGSLRandom();
  62. for ( int i = 0 ; i < count ; i++ )
  63. {
  64. // refactor-nice.pl: check this substitution
  65. // old: Vector x ( alpha.size() );
  66. NICE::Vector x ( alpha.size() );
  67. gsl_ran_dirichlet (randomGSL, alpha.size(), alpha.getDataPointerConst(), x.getDataPointer() );
  68. samples.push_back ( x );
  69. }
  70. #else
  71. #warning "PDFDirichlet::sample: this function needs the GNU Scientific Library"
  72. fprintf (stderr, "PDFDirichlet::sample: this function needs the GNU Scientific Library\n");
  73. exit(-1);
  74. #endif
  75. }