/** * @file PDFDirichlet.cpp * @brief Normal Distribution / Gaussian PDF * @author Erik Rodner * @date 01/29/2008 */ #include #include "vislearning/math/pdf/PDFDirichlet.h" #include "vislearning/math/pdf/gslRandomNumberGenerator.h" using namespace OBJREC; using namespace std; // refactor-nice.pl: check this substitution // old: using namespace ice; using namespace NICE; PDFDirichlet::PDFDirichlet( double _alpha, int dimension ) : alpha(dimension) { for ( int i = 0 ; i < dimension ; i++ ) alpha[i] = _alpha / dimension; } // refactor-nice.pl: check this substitution // old: PDFDirichlet::PDFDirichlet ( const Vector & _alpha ) : alpha(_alpha) PDFDirichlet::PDFDirichlet ( const NICE::Vector & _alpha ) : alpha(_alpha) { } PDFDirichlet::~PDFDirichlet() { } // refactor-nice.pl: check this substitution // old: double PDFDirichlet::getNLogDensity ( const Vector & x ) const double PDFDirichlet::getNLogDensity ( const NICE::Vector & x ) const { #ifdef NICE_USELIB_GSL return gsl_ran_dirichlet_lnpdf ( alpha.size(), alpha.getDataPointerConst(), x.getDataPointerConst() ); #else #warning "PDFDirichlet::getNLogDensity: this function needs the GNU Scientific Library" fprintf (stderr, "PDFDirichlet::getNLogDensity: this function needs the GNU Scientific Library\n"); exit(-1); return 0.0; #endif } // refactor-nice.pl: check this substitution // old: double PDFDirichlet::getProb ( const Vector & x ) const double PDFDirichlet::getProb ( const NICE::Vector & x ) const { #ifdef NICE_USELIB_GSL return gsl_ran_dirichlet_pdf ( alpha.size(), alpha.getDataPointerConst(), x.getDataPointerConst() ); #else #warning "PDFDirichlet::getProb: this function needs the GNU Scientific Library" fprintf (stderr, "PDFDirichlet::getProb: this function needs the GNU Scientific Library\n"); exit(-1); return 0.0; #endif } int PDFDirichlet::getDimension () const { return alpha.size(); } void PDFDirichlet::sample ( VVector & samples, int count ) const { #ifdef NICE_USELIB_GSL initGSLRandom(); for ( int i = 0 ; i < count ; i++ ) { // refactor-nice.pl: check this substitution // old: Vector x ( alpha.size() ); NICE::Vector x ( alpha.size() ); gsl_ran_dirichlet (randomGSL, alpha.size(), alpha.getDataPointerConst(), x.getDataPointer() ); samples.push_back ( x ); } #else #warning "PDFDirichlet::sample: this function needs the GNU Scientific Library" fprintf (stderr, "PDFDirichlet::sample: this function needs the GNU Scientific Library\n"); exit(-1); #endif }