DGtal  1.2.0
testMetrics-benchmark.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
35 #include "DGtal/geometry/volumes/distance/InexactPredicateLpSeparableMetric.h"
36 #include <boost/lexical_cast.hpp>
38 
39 using namespace std;
40 using namespace DGtal;
41 
43 // Functions for testing class Metrics-benchmark.
45 
46 template<int p>
47 bool runATest( unsigned int maxTest)
48 {
51  double sum=0.0, d=0,d2=0, MSE=0;
52  std::string txt = "Testing Exponent" + boost::lexical_cast<string>(p);
53 
54 
55  DGtal::Dimension dim = 1000;
56  trace.beginBlock(txt);
57  trace.beginBlock("Exact Predicate run");
58  for(unsigned int i=0; i< maxTest; ++i)
59  {
60  Z3i::Point P( rand() % dim,rand() % dim ,rand() % dim );
61  Z3i::Point Q( rand() % dim, rand() % dim, rand() % dim);
62  sum += exactMetric(P,Q);
63  }
64 
65  trace.endBlock();
66 
67  trace.beginBlock("Inexact Predicate run");
68  for(unsigned int i=0; i< maxTest; ++i)
69  {
70  Z3i::Point P( rand() % dim,rand() % dim ,rand() % dim );
71  Z3i::Point Q( rand() % dim, rand() % dim, rand() % dim);
72  sum += approxMetric(P,Q);
73  }
74  trace.endBlock();
75 
76 
77  trace.beginBlock("Both with comparison run");
78  for(unsigned int i=0; i< maxTest; ++i)
79  {
80  Z3i::Point P( rand() % dim,rand() % dim ,rand() % dim );
81  Z3i::Point Q( rand() % dim, rand() % dim, rand() % dim);
82  d = exactMetric(P,Q);
83  d2 = approxMetric(P,Q);
84  MSE += (d-d2)*(d-d2);
85  }
86  trace.endBlock();
87  trace.info() << "Mean Square Error = "<<MSE<<std::endl;
88  trace.endBlock();
89  return true;
90 }
91 
92 
93 
95 // Standard services - public :
96 
97 int main( int argc, char** argv )
98 {
99  trace.beginBlock ( "Testing class Metrics-benchmark" );
100  trace.info() << "Args:";
101  for ( int i = 0; i < argc; ++i )
102  trace.info() << " " << argv[ i ];
103  trace.info() << endl;
104 
105  bool res = runATest<2>(1000000) &&
106  runATest<4>(10000000);
107  runATest<6>(1000000);
108  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
109  trace.endBlock();
110  return res ? 0 : 1;
111 }
112 // //
Aim: implements separable l_p metrics with exact predicates.
Aim: implements separable l_p metrics with approximated predicates.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Definition: Common.h:137
Trace trace
Definition: Common.h:154
bool runATest(unsigned int maxTest)
int main(int argc, char **argv)
unsigned int dim(const Vector &z)