DGtal
1.4.0
Loading...
Searching...
No Matches
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
{
49
ExactPredicateLpSeparableMetric<Z3i::Space, p>
exactMetric;
50
InexactPredicateLpSeparableMetric<Z3i::Space>
approxMetric(p);
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
// //
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition
ExactPredicateLpSeparableMetric.h:88
DGtal::InexactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with approximated predicates.
Definition
InexactPredicateLpSeparableMetric.h:82
DGtal::PointVector< dim, Integer >
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::Dimension
DGtal::uint32_t Dimension
Definition
Common.h:136
DGtal::trace
Trace trace
Definition
Common.h:153
std
STL namespace.
main
int main()
Definition
testBits.cpp:56
dim
#define dim
Definition
testImageContainerByHashTree.cpp:40
runATest
bool runATest(unsigned int maxTest)
Definition
testMetrics-benchmark.cpp:47
tests
geometry
volumes
distance
testMetrics-benchmark.cpp
Generated on Mon Jun 10 2024 17:36:11 for DGtal by
1.11.0