33 #include "DGtal/math/Statistic.h"
34 #include "DGtal/math/Histogram.h"
39 using namespace DGtal;
48 double getRandomNumber(
double first,
double last )
50 double v = ((double)rand()) / (
double) RAND_MAX;
51 return v * ( last - first ) + first;
54 bool testHistogramUniform()
56 unsigned int nbok = 0;
60 for(
unsigned int k=0; k < 1000; k++)
61 stat.addValue( getRandomNumber( -1.0, 1.0 ) );
65 hist.
addValues( stat.begin(), stat.end() );
67 for (
unsigned int i = 0; i < hist.
size(); ++i )
68 std::cout << i <<
" " << hist.
pdf( i ) <<
" " << hist.
cdf( i ) << std::endl;
69 ++nb, nbok += hist.
cdf( hist.
size()-1 ) > 0.9999 ? 1 : 0;
73 bool testHistogramGaussian()
75 unsigned int nbok = 0;
79 for(
unsigned int k=0; k < 1000; k++)
80 stat.addValue( getRandomNumber( -1.0, 1.0 ) + getRandomNumber( -1.0, 1.0 ) );
84 hist.
addValues( stat.begin(), stat.end() );
86 for (
unsigned int i = 0; i < hist.
size(); ++i )
87 std::cout << i <<
" " << hist.
pdf( i ) <<
" " << hist.
cdf( i ) << std::endl;
88 ++nb, nbok += hist.
cdf( hist.
size()-1 ) > 0.9999 ? 1 : 0;
92 bool testHistogramGaussian2()
94 unsigned int nbok = 0;
98 for(
unsigned int k=0; k < 1000; k++)
99 stat.addValue( getRandomNumber( -1.0, 1.0 ) + getRandomNumber( -1.0, 1.0 )
100 + getRandomNumber( -1.0, 1.0 ) );
104 hist.
addValues( stat.begin(), stat.end() );
106 for (
unsigned int i = 0; i < hist.
size(); ++i )
107 std::cout << i <<
" " << hist.
pdf( i ) <<
" " << hist.
cdf( i ) << std::endl;
108 ++nb, nbok += hist.
cdf( hist.
size()-1 ) > 0.9999 ? 1 : 0;
116 int main(
int,
char** )
120 bool res = testHistogramUniform()
121 && testHistogramGaussian()
122 && testHistogramGaussian2();
123 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
void beginBlock(const std::string &keyword="")
void addValues(TInputIterator it, TInputIterator itE)
Aim: Represents a typical histogram in statistics, which is a discrete estimate of the probability di...
Aim: This class processes a set of sample values for one variable and can then compute different stat...
DGtal is the top-level namespace which contains all DGtal functions and types.
void init(Clone< Binner > binner)