34 : m_x_sampling(
std::move(other.m_x_sampling)), m_y_sampling(
std::move(other.m_y_sampling)) {}
51 : m_x_sampling(x_sampling), m_y_sampling(y_sampling) {
52 if (x_sampling.
size() != y_sampling.
size()) {
58 auto iter = sampling.
begin();
59 while (iter != sampling.
end()) {
69 auto iter = sampling.
begin();
70 while (iter != sampling.
end()) {
71 xs.push_back((*iter).first);
72 ys.push_back((*iter).second);
81 auto iter_pdf = pdf_sampling.
cbegin();
83 while (iter_pdf != pdf_sampling.
cend()) {
85 cumul.push_back(total);
97 cumul.push_back(*iter / total);
106 if (ratio > 1. || ratio < 0.) {
107 throw Elements::Exception(
"Cumulative::findValue : ratio parameter must be in range [0,1]");
119 double begin_value = *iter_x;
120 double tray = *iter_y;
126 double end_value = *(--iter_x);
130 case TrayPosition::begin:
131 result = begin_value;
133 case TrayPosition::middle:
134 result = 0.5 * (begin_value + end_value);
136 case TrayPosition::end:
146 if (rate > 1. || rate <= 0.) {
147 throw Elements::Exception(
"Cumulative::findMinInterval : rate parameter must be in range ]0,1]");
161 while (iter_2_x !=
m_x_sampling.
cend() && (*iter_2_y - *iter_1_y + first_correction) < rate) {
168 if ((*iter_2_x - *iter_1_x) <= (*max_x - *min_x)) {
174 first_correction = 0.;
182 if (rate > 1. || rate <= 0.) {
183 throw Elements::Exception(
"Cumulative::findCenteredInterval : rate parameter must be in range ]0,1]");
196 if ((*iter_y) < max_value) {
197 double tray = *iter_y;
208 double max_x = *iter_x;
213 double max_x = *iter_x;
Class for build cumulative from PDF and extract feature out of it.
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
Cumulative(Cumulative &&other)
move constructor
Cumulative & operator=(Cumulative &&other)
move assignation operator
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.