56 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t_start);
60 inline void stopTimer(
string msg,
int ID = 0,
double factor = 1) {
62 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t_end);
64 timespec& t_start =
TIMERS.back();
65 TIMER_LOG << msg <<
": " << factor * ((t_end.tv_sec - t_start.tv_sec) +
double(t_end.tv_nsec - t_start.tv_nsec) / 1e9) <<
" secs." << endl;
71 cout <<
"------------- TIME -----------" << endl;
73 cout <<
"------------------------------" << endl;
76 void testOutput(
string msg,
double out,
double actual,
double epsilon = 1e-9) {
77 double diff = fabs(out - actual);
79 OUTPUT_LOG <<
"OK - " << msg <<
": " << out << endl;
81 OUTPUT_LOG <<
"DIFF - " << msg <<
": " << out <<
" - " << actual <<
" = " << diff << endl;
87 cout <<
"----------- OUTPUT -----------" << endl;
89 cout <<
"------------------------------" << endl;
114 cout << H_msg << endl;
118 cout << H_received->
toString() << endl;
141 cout <<
"Before initialization: " << exact2.
toString() << endl;
144 cout <<
"Mixture: " << endl << mix2.
toString() << endl;
147 for (
int i = 0; i < 1000; ++i) {
150 cout <<
"Density of mixture at " << mean2 <<
" = " << d << endl << endl;
152 cout <<
"Converting to msg ..." << endl << endl;
153 problib::PDF pdf_msg;
155 cout <<
"Result:" << endl << pdf_msg << endl;
157 cout <<
"Converting back to pdf ..." << endl << endl;
159 cout <<
"Result:" << endl << received_pdf->
toString() << endl << endl;
161 cout <<
"Density of mixture at " << mean2 <<
" = " << received_pdf->
getLikelihood(exact2) << endl << endl;
165 cout <<
"Creating pmf ..." << endl;
175 cout << pmf.
toString() << endl << endl;
177 cout <<
"Updating pmf ..." << endl;
179 cout << pmf.
toString() << endl << endl;
185 cout <<
"Updating pmf ..." << endl;
193 for(
int i = 0; i < 1000; ++i) {
198 cout << pmf_copy.
toString() << endl;
201 cout <<
"Converting to msg ..." << endl << endl;
202 problib::PDF pmf_msg;
204 cout <<
"Result:" << endl << pmf_msg << endl;
206 cout <<
"Converting back to pdf ..." << endl << endl;
208 cout <<
"Result:" << endl << received_pdf2->
toString() << endl << endl;
210 delete received_pdf2;
212 cout <<
"Testing simple population of msg for exact (string) value ..." << endl;
213 problib::PDF exact_str;
214 exact_str.exact_value_str =
"test";
216 cout <<
"exact_str:" << endl << pdf_exact_str->
toString(
" ") << endl << endl;
217 delete pdf_exact_str;
219 cout <<
"Testing simple population of msg for exact (real) value ..." << endl;
220 problib::PDF exact_real;
221 exact_real.exact_value_vec.push_back(1);
222 exact_real.exact_value_vec.push_back(1);
223 exact_real.exact_value_vec.push_back(1);
225 cout <<
"exact_real:" << endl << pdf_exact_real->
toString(
" ") << endl << endl;
230 for(
int i = 0; i < 1000000; ++i) {
234 stopTimer(
"Likelihood on mixture", (
double)1 / 1000000);
236 cout <<
"Likelihood with mixture = " << mix2.
getLikelihood(*pdf_exact_real) << endl << endl;
238 testOutput(
"Likelihood with mixture", d2, 0.0612611897752479);
240 printf(
"%.16f\n", d2);
247 cout << mix_copy.
toString() << endl;
250 testOutput(
"Likelihood with mixture (copy)", d3, d2);
252 delete pdf_exact_real;
255 int main(
int argc,
char **argv) {
PDF * msgToPDF(const problib::PDF &msg)
Converts a PDF ROS message to a PDF object.
This class represents the weighted sum of a finite set of probability density functions.
void startTimer(int ID=0)
This class represents a multi-variate Gaussian (Normal) distribution.
void addPDF(const PDF &pdf, double priority)
void clear()
Removes all components.
void testOutput(string msg, double out, double actual, double epsilon=1e-9)
void addComponent(const PDF &pdf, double w)
Adds a component pdf with given weight.
void setDomainSize(int domain_size)
Sets the domain size of this discrete distribution.
void setMean(const arma::vec &mu)
Sets the mean of the Gaussian.
void stopTimer(string msg, int ID=0, double factor=1)
std::string toString(const std::string &indent="") const
Represents the PMF as a string for easier console output.
double getLikelihood(const PDF &pdf) const
void update(const pbl::PMF &pmf)
int main(int argc, char **argv)
void setProbability(const std::string &value, double p)
Set the probability of a given value.
virtual std::string toString(const std::string &indent="") const =0
std::string toString(const std::string &indent="") const
Represents the Mixture as a string for easier console output.
This class represents a discrete probability distribution (or probability mass function). Currently, this PMF can only take strings as values.
virtual double getLikelihood(const PDF &pdf) const =0
std::string toString(const std::string &indent="") const
Represents the Gaussian as a string for easier console output.
void PDFtoMsg(const PDF &pdf, problib::PDF &msg)
Converts a PDF object to a ROS message.