DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Histogram.h
1
16
17
#pragma once
18
30
31
#if defined(Histogram_RECURSES)
32
#error Recursive header files inclusion detected in Histogram.h
33
#else
// defined(Histogram_RECURSES)
35
#define Histogram_RECURSES
36
37
#if !defined Histogram_h
39
#define Histogram_h
40
42
// Inclusions
43
#include <iostream>
44
#include "DGtal/base/Common.h"
45
#include "DGtal/base/Clone.h"
46
#include "DGtal/math/CBinner.h"
47
#include "DGtal/kernel/CEuclideanRing.h"
48
#include "DGtal/math/Statistic.h"
50
51
namespace
DGtal
52
{
63
template
<
typename
TQuantity>
64
struct
RegularBinner
{
65
typedef
TQuantity
Quantity
;
66
typedef
RegularBinner< Quantity >
Self
;
67
typedef
DGtal::uint32_t
Bin
;
68
69
Quantity
myMin
;
70
Quantity
myMax
;
71
Bin
myNb
;
72
Quantity
myWidth
;
73
84
RegularBinner
(
const
Quantity
& min,
const
Quantity
&
max
,
Bin
n )
85
:
myMin
( min ),
myMax
(
max
),
myNb
( n )
86
{
87
ASSERT(
max
> min );
88
ASSERT( n > 0 );
89
myWidth
= (
max
- min ) /
static_cast<
Quantity
>
( n );
90
}
91
95
inline
Bin
size
()
const
96
{
97
return
myNb
;
98
}
99
105
inline
Bin
operator()
(
const
Quantity
& q )
const
106
{
107
if
( q <=
myMin
)
return
NumberTraits<Bin>::ZERO
;
108
else
if
( q >=
myMax
)
return
myNb
-
NumberTraits<Bin>::ONE
;
109
else
return
static_cast<
Bin
>
( floor(
NumberTraits<Quantity>::castToDouble
( ( q -
myMin
) /
myWidth
) ) );
110
}
111
};
112
114
// template class Histogram
143
template
<
typename
TQuantity,
144
typename
TBinner = RegularBinner< TQuantity > >
145
class
Histogram
146
{
147
public
:
148
BOOST_CONCEPT_ASSERT
((
concepts::CEuclideanRing< TQuantity >
));
149
BOOST_CONCEPT_ASSERT
((
concepts::CBinner< TBinner >
));
150
BOOST_STATIC_ASSERT
(( boost::is_same< TQuantity, typename TBinner::Quantity >::value ));
151
152
// ----------------------- public types ------------------------------
153
public
:
154
typedef
TQuantity
Quantity
;
155
typedef
TBinner
Binner
;
156
typedef
Histogram< Quantity, Binner >
Self
;
157
typedef
typename
Binner::Bin
Bin
;
158
typedef
DGtal::uint64_t
Size
;
159
typedef
std::vector<Size>
Container
;
160
typedef
Container::const_iterator
ConstIterator
;
161
166
enum
Formula
{
SquareRoot
,
167
Sturges
,
168
Rice
,
169
Scott
};
170
// ----------------------- Standard services ------------------------------
171
public
:
172
176
~Histogram
();
177
181
Histogram
();
182
186
void
clear
();
187
191
void
init
(
Clone<Binner>
binner );
192
197
void
init
(
Formula
formula,
const
Statistic<Quantity>
& stat );
198
203
void
init
(
Bin
nbBins,
const
Statistic<Quantity>
& stat );
204
209
void
addValue
(
Quantity
q );
210
217
template
<
typename
TInputIterator>
218
void
addValues
( TInputIterator it, TInputIterator itE );
219
223
void
terminate
();
224
229
Bin
bin
(
Quantity
q )
const
;
230
234
Bin
size
()
const
;
235
240
Size
area
()
const
;
241
246
Size
nb
(
Bin
b )
const
;
247
253
Size
accumulation
(
Bin
b )
const
;
254
259
double
pdf
(
Bin
b )
const
;
260
265
double
cdf
(
Bin
b )
const
;
266
267
// ----------------------- Interface --------------------------------------
268
public
:
269
274
void
selfDisplay
( std::ostream & out )
const
;
275
280
bool
isValid
()
const
;
281
282
// ------------------------- Protected Data ------------------------------
283
protected
:
285
const
Binner
*
myBinner
;
287
Container
myHistogram
;
289
Container
myCumulativeHistogram
;
290
291
// ------------------------- Private Data --------------------------------
292
private
:
293
294
// ------------------------- Hidden services ------------------------------
295
private
:
296
302
Histogram
(
const
Histogram
& other );
303
310
Histogram
&
operator=
(
const
Histogram
& other );
311
312
// ------------------------- Internals ------------------------------------
313
private
:
317
void
prepare
(
Bin
size
);
318
319
320
};
// end of class Histogram
321
322
329
template
<
typename
TQuantity,
typename
TBinner>
330
std::ostream&
331
operator<<
( std::ostream & out,
const
Histogram<TQuantity, TBinner>
&
object
);
332
333
}
// namespace DGtal
334
335
337
// Includes inline functions.
338
#include "DGtal/math/Histogram.ih"
339
340
// //
342
343
#endif
// !defined Histogram_h
344
345
#undef Histogram_RECURSES
346
#endif
// else defined(Histogram_RECURSES)
DGtal::Clone
Aim: This class encapsulates its parameter class to indicate that the given parameter is required to ...
Definition
Clone.h:266
DGtal::Histogram< Quantity, Binner >
DGtal::Histogram< Quantity, Binner >::ConstIterator
Container::const_iterator ConstIterator
Definition
Histogram.h:160
DGtal::Histogram< Quantity, Binner >::Size
DGtal::uint64_t Size
Definition
Histogram.h:158
DGtal::Histogram::accumulation
Size accumulation(Bin b) const
DGtal::Histogram::addValues
void addValues(TInputIterator it, TInputIterator itE)
DGtal::Histogram::init
void init(Bin nbBins, const Statistic< Quantity > &stat)
DGtal::Histogram::pdf
double pdf(Bin b) const
DGtal::Histogram< Quantity, Binner >::Bin
Binner::Bin Bin
Definition
Histogram.h:157
DGtal::Histogram::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::Histogram::operator=
Histogram & operator=(const Histogram &other)
DGtal::Histogram::prepare
void prepare(Bin size)
DGtal::Histogram< Quantity, Binner >::Container
std::vector< Size > Container
Definition
Histogram.h:159
DGtal::Histogram::isValid
bool isValid() const
DGtal::Histogram::init
void init(Formula formula, const Statistic< Quantity > &stat)
DGtal::Histogram::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CEuclideanRing< TQuantity >))
DGtal::Histogram::Formula
Formula
Definition
Histogram.h:166
DGtal::Histogram< Quantity, Binner >::Scott
@ Scott
Definition
Histogram.h:169
DGtal::Histogram< Quantity, Binner >::Sturges
@ Sturges
Definition
Histogram.h:167
DGtal::Histogram< Quantity, Binner >::Rice
@ Rice
Definition
Histogram.h:168
DGtal::Histogram::SquareRoot
@ SquareRoot
Definition
Histogram.h:166
DGtal::Histogram::nb
Size nb(Bin b) const
DGtal::Histogram::~Histogram
~Histogram()
DGtal::Histogram::addValue
void addValue(Quantity q)
DGtal::Histogram::Quantity
TQuantity Quantity
Definition
Histogram.h:154
DGtal::Histogram::clear
void clear()
DGtal::Histogram::size
Bin size() const
DGtal::Histogram< Quantity, Binner >::myBinner
const Binner * myBinner
Definition
Histogram.h:285
DGtal::Histogram::Binner
TBinner Binner
Definition
Histogram.h:155
DGtal::Histogram< Quantity, Binner >::myCumulativeHistogram
Container myCumulativeHistogram
Definition
Histogram.h:289
DGtal::Histogram::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT((boost::is_same< TQuantity, typename TBinner::Quantity >::value))
DGtal::Histogram::Histogram
Histogram()
DGtal::Histogram::cdf
double cdf(Bin b) const
DGtal::Histogram::Histogram
Histogram(const Histogram &other)
DGtal::Histogram::init
void init(Clone< Binner > binner)
DGtal::Histogram< Quantity, Binner >::myHistogram
Container myHistogram
Definition
Histogram.h:287
DGtal::Histogram::bin
Bin bin(Quantity q) const
DGtal::Histogram::area
Size area() const
DGtal::Histogram::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CBinner< TBinner >))
DGtal::Histogram::terminate
void terminate()
DGtal::Histogram::Self
Histogram< Quantity, Binner > Self
Definition
Histogram.h:156
DGtal::Statistic
Aim: This class processes a set of sample values for one variable and can then compute different stat...
Definition
Statistic.h:70
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::uint64_t
std::uint64_t uint64_t
unsigned 64-bit integer.
Definition
BasicTypes.h:64
DGtal::uint32_t
std::uint32_t uint32_t
unsigned 32-bit integer.
Definition
BasicTypes.h:62
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::NumberTraitsImpl< std::decay< T >::type >::ONE
static const T ONE
Definition
NumberTraits.h:103
DGtal::NumberTraitsImpl< std::decay< T >::type >::ZERO
static const T ZERO
Definition
NumberTraits.h:100
DGtal::NumberTraitsImpl< std::decay< T >::type >::castToDouble
static double castToDouble(const T &aT)
Definition
NumberTraits.h:164
DGtal::RegularBinner< Quantity >
DGtal::RegularBinner::Quantity
TQuantity Quantity
Definition
Histogram.h:65
DGtal::RegularBinner< Quantity >::myMin
Quantity myMin
Definition
Histogram.h:69
DGtal::RegularBinner::RegularBinner
RegularBinner(const Quantity &min, const Quantity &max, Bin n)
Definition
Histogram.h:84
DGtal::RegularBinner::Self
RegularBinner< Quantity > Self
Definition
Histogram.h:66
DGtal::RegularBinner::operator()
Bin operator()(const Quantity &q) const
Definition
Histogram.h:105
DGtal::RegularBinner< Quantity >::myNb
Bin myNb
Definition
Histogram.h:71
DGtal::RegularBinner< Quantity >::Bin
DGtal::uint32_t Bin
Definition
Histogram.h:67
DGtal::RegularBinner::size
Bin size() const
Definition
Histogram.h:95
DGtal::RegularBinner< Quantity >::myMax
Quantity myMax
Definition
Histogram.h:70
DGtal::RegularBinner< Quantity >::myWidth
Quantity myWidth
Definition
Histogram.h:72
DGtal::concepts::CBinner
Aim: Represents an object that places a quantity into a bin, i.e. a functor that associates a natural...
Definition
CBinner.h:98
DGtal::concepts::CEuclideanRing
Aim: Defines the mathematical concept equivalent to a unitary commutative ring with a division operat...
Definition
CEuclideanRing.h:88
max
int max(int a, int b)
Definition
testArithmeticalDSS.cpp:1108
src
DGtal
math
Histogram.h
Generated on
for DGtal by
1.18.0