22 #ifndef CRNHISTOGRAM_HEADER
23 #define CRNHISTOGRAM_HEADER
70 double left_bound = std::numeric_limits<double>::infinity();
71 double right_bound = -std::numeric_limits<double>::infinity();
77 for (
auto it = it_begin; it != it_end; ++it)
80 size_t c = it->second;
91 double range = right_bound - left_bound;
97 nb_bins = (size_t) sqrt(
double(cardinal));
98 delta = range / double(nb_bins);
102 nb_bins = 1 + (size_t) (log(
double(cardinal)) / log(2.0));
103 delta = range / double(nb_bins);
110 for (
auto it = it_begin; it != it_end; ++it)
111 m += it->first * ((
double)it->second / (
double)cardinal);
113 for (
auto it = it_begin; it != it_end; ++it)
115 double diff = it->first - m;
117 v += (diff * diff) * ((
double)it->second / (double)cardinal);
120 delta = 3.5 * sqrt(v) / pow(
double(cardinal), (1.0 / 3.0));
121 nb_bins = 1 + (size_t) ((right_bound - left_bound) / delta);
125 delta = range / double(nb_bins);
130 bins = std::vector<unsigned int>(nb_bins + 1, 0u);
136 SetBin(0, (
unsigned int)cardinal);
139 for (
auto it = it_begin; it != it_end; ++it)
141 size_t id = (size_t)((it->first - left_bound) / delta);
157 size_t Size() const noexcept {
return bins.size();}
159 unsigned int*
GetBins() {
return &(bins.front());}
161 const unsigned int*
GetBins()
const {
return &(bins.front());}
164 void SetBin(
size_t k,
unsigned int v);
167 void IncBin(
size_t k,
unsigned int i = 1u);
170 unsigned int GetBin(
size_t k)
const;
175 const unsigned int&
operator[](
size_t k)
const {
return bins[k]; }
194 unsigned int Max()
const;
197 unsigned int Min()
const;
217 std::vector<size_t>
Modes()
const;
255 void Resize(
size_t newsize);
284 std::vector<unsigned int>
Std() && {
return std::move(bins); }
292 using datatype = std::vector<unsigned int>;
294 unsigned int compression;
double Deviation(double m) const
Standard deviation on class indexes, having mean value.
xml::Element Serialize(xml::Element &parent) const
Dumps the object to an XML element. Unsafe.
double JeffreyDivergence(const Histogram &h) const
Jeffrey divergence between two histograms.
#define CRN_SERIALIZATION_CONSTRUCTOR(classname)
Defines a default constructor from xml element.
double Entropy() const
the entropy
double IntersectionDivergence(const Histogram &h) const
Intersection divergence between two histograms.
void Deserialize(xml::Element &el)
Initializes the object from an XML element. Unsafe.
void CircularAverageSmoothing(size_t d)
Smoothing circular histogram.
double KolmogorovSmirnovDistance(const Histogram &h) const
Kolmogorov-Smirnov distance between two histograms.
void IncBin(size_t k, unsigned int i=1u)
Increments a bin value.
std::vector< unsigned int > Std()&&
unsigned int Max() const
Maximal count value.
void SetCeiling(unsigned int m)
Set maximal count value to m.
size_t Argmax() const
First class having a maximal count value.
size_t Argmin() const
First class having a minimal count value.
unsigned int GetBin(size_t k) const
Get a bin value.
ImageBW MakeRadialImageBW(size_t radius) const
returns the circular histogram image
A UTF32 character string class.
const unsigned int & operator[](size_t k) const
Access a bin value (fast and unsafe)
double Mean() const
Mean value on class indexes.
Histogram MakeIntersection(const Histogram &h) const
Intersection between two histograms.
void Append(const Histogram &h)
Appends an histogram to the current.
double EMD(const Histogram &h) const
Earth Mover's Distance.
ImageBW MakeImageBW(size_t height) const
returns the histogram image
void SetBin(size_t k, unsigned int v)
Modify a bin value.
double Variance() const
Variance on class indexes.
size_t Size() const noexcept
Returns the number of bins.
void Cumulate()
Cumulates the values from 0 to end.
double Correlation(const Histogram &h) const
Correlation between two histograms.
double Distance(const Int &i1, const Int &i2) noexcept
const unsigned int * GetBins() const
Returns a reference to the internal pointer on the bins.
Histogram & operator=(const Histogram &)=delete
double Chi2(const Histogram &h) const
Correlation between two histograms.
size_t MedianValue() const
Computes the median value.
std::vector< size_t > Modes() const
Returns the modes.
std::vector< size_t > StableModes() const
Returns the stable modes.
size_t Fisher() const
Computes the Fisher threshold.
double MinkowskiDistance(const Histogram &h, double r) const
Minkowski distance between two histograms.
Mother class for integer histograms.
Histogram()
Default constructor.
void AverageSmoothing(size_t d)
Smoothing histogram.
double CEMD(const Histogram &h) const
Circular Earth Mover's Distance.
Histogram MakePopulationHistogram() const
Creates an histogram from population.
unsigned int * GetBins()
Returns the internal pointer on the bins.
#define CRN_DECLARE_CLASS_CONSTRUCTOR(classname)
Declares a class constructor.
unsigned int & operator[](size_t k)
Access a bin value (fast and unsafe)
size_t EntropyThreshold() const
Computes the entropy threshold.
String ToString() const
Dumps bins to a string.
unsigned int Min() const
Minimal count value.
double Deviation() const
Standard deviation on class indexes.
unsigned int CumulateBins() const
Cumulate all bins.
void ScaleMaxTo(unsigned int m)
Scale maximal count to m.
Histogram(ITER it_begin, ITER it_end, DesignHeuristic m=DesignHeuristic::STURGES, size_t nb_bins=(size_t) 1)
double MatchDistance(const Histogram &h) const
Match distance between two histograms.
void Resize(size_t newsize)
Resizes the histogram.