PDFDirichlet.cpp 2.6 KB

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