34 : m_x_sampling(x_sampling), m_y_sampling(y_sampling) {
35 if (x_sampling.
size() != y_sampling.
size()) {
41 auto iter = sampling.
begin();
42 while (iter != sampling.
end()) {
52 auto iter = sampling.
begin();
53 while (iter != sampling.
end()) {
54 xs.push_back((*iter).first);
55 ys.push_back((*iter).second);
64 auto iter_pdf = pdf_sampling.
cbegin();
66 while (iter_pdf != pdf_sampling.
cend()) {
68 cumul.push_back(total);
80 cumul.push_back(*iter / total);
89 if (ratio > 1. || ratio < 0.) {
90 throw Elements::Exception(
"Cumulative::findValue : ratio parameter must be in range [0,1]");
102 double begin_value = *iter_x;
103 double tray = *iter_y;
109 double end_value = *(--iter_x);
114 result = begin_value;
117 result = 0.5 * (begin_value + end_value);
129 if (rate > 1. || rate <= 0.) {
130 throw Elements::Exception(
"Cumulative::findMinInterval : rate parameter must be in range ]0,1]");
144 while (iter_2_x !=
m_x_sampling.
cend() && (*iter_2_y - *iter_1_y + first_correction) < rate) {
151 if ((*iter_2_x - *iter_1_x) <= (*max_x - *min_x)) {
157 first_correction = 0.;
165 if (rate > 1. || rate <= 0.) {
166 throw Elements::Exception(
"Cumulative::findCenteredInterval : rate parameter must be in range ]0,1]");
179 if ((*iter_y) < max_value) {
180 double tray = *iter_y;
191 double max_x = *iter_x;
196 double max_x = *iter_x;
Class for build cumulative from PDF and extract feature out of it.
Cumulative(Cumulative &&other)=default
move constructor
TrayPosition
when looking for the position having a given value, one may encounter tray where the value is constan...
std::vector< double > m_x_sampling
std::pair< double, double > findCenteredInterval(double rate) const
return the horizontal interval starting where the Cumulative has value (1-ratio)/2 and ending where t...
std::vector< double > m_y_sampling
void normalize()
Normalize the Cumulative. After calling this function the last vertical value is 1....
double findValue(double ratio, TrayPosition position=TrayPosition::middle) const
Find the first horizontal sample which vertical value is bigger or equal to the ratio value....
std::pair< double, double > findMinInterval(double rate) const
Scan the horizontal axis looking for the smallest x-interval for which the vertical interval is at le...
static Cumulative fromPdf(std::vector< double > &x_sampling, std::vector< double > &pdf_sampling)
Factory from the sampling of a PDF. The Cumulative vertical samples are build as the sum of the the p...
This module provides an interface for accessing two dimensional datasets (pairs of (X,...
const_iterator begin() const
Returns a const iterator to the first pair of the dataset.
const_iterator end() const
Returns a const iterator to the one after last pair dataset.