42 auto iter = pdf.
begin();
43 while (iter != pdf.
end()) {
44 xs.push_back((*iter).first);
45 ys.push_back((*iter).second);
56 for (
auto iter = pdf.
begin(); iter != pdf.
end(); ++iter) {
71 double peak_value = pdf[center_index];
72 double threshold = (1.0-merge_ratio)*peak_value;
74 size_t max_x = pdf.
size()-1;
76 for (
size_t index = 0; index <= center_index; ++index) {
77 size_t position = center_index-index;
78 if (position == 0 || pdf[position] == 0) {
81 if ((pdf[position] < threshold && pdf[position-1] >= pdf[position])) {
89 for (
size_t position = center_index; position <= pdf.
size(); ++position) {
90 if (position == pdf.
size()-1 || pdf[position] == 0) {
93 if ((pdf[position] < threshold && pdf[position+1] >= pdf[position] )) {
108 for (
size_t index = min_x; index <= max_x; ++index) {
111 dx = pdf.first[index+1] - pdf.first[index];
112 }
else if (index == pdf.first.size()-1) {
113 dx = pdf.first[index] - pdf.first[index-1];
115 dx = (pdf.first[index+1] - pdf.first[index-1])/2.0;
118 num += pdf.first[index]*pdf.second[index]*dx;
119 area += pdf.second[index]*dx;
132 if (x_index>= pdf.first.size()) {
139 }
else if (x_index +1 == pdf.first.size()) {
143 double x0 = pdf.first[x_index-1];
144 double y0 = pdf.second[x_index-1];
146 double x1 = pdf.first[x_index];
147 double y1 = pdf.second[x_index];
149 double x2 = pdf.first[x_index+1];
150 double y2 = pdf.second[x_index+1];
152 double denom = 2*((x1-x0)*y2 - (x2-x0)*y1 + (x2-x1)*y0);
153 double num = (x1*x1-x0*x0)*y2 - (x2*x2-x0*x0)*y1 + (x2*x2-x1*x1)*y0;
162 if (x_max < pdf.first.front()) {
163 x_max = pdf.first.front();
164 }
else if (x_max > pdf.first.back()) {
165 x_max = pdf.first.back();
178 for (
size_t index = min_x; index <= max_x; ++index) {
179 flatterned[index] = value;
192 for (
size_t idx = 0; idx < n; ++idx) {
194 auto min_max =
catchPeak(pdf_xy.second, peak_index, merge_ratio);
195 auto mean_area =
avgArea(pdf_xy, min_max.first, min_max.second);
198 result.push_back(
ModeInfo(pdf_xy.first[peak_index], mean_area.first, max_inter, mean_area.second));
199 pdf_xy =
flatternPeak(pdf_xy, min_max.first, min_max.second, 0.0);
206 auto pdf_xy =
getXYs(pdf);
216 double total_area =
avgArea(pdf_xy, 0, x_sampling.
size() -1).second;
225 auto min_max =
catchPeak(pdf_xy.second, peak_index, merge_ratio);
226 auto mean_area =
avgArea(pdf_xy, min_max.first, min_max.second);
227 auto max_sample = pdf_xy.first[peak_index];
229 auto new_mode =
ModeInfo(max_sample, mean_area.first, interp_max_value, mean_area.second);
231 auto iter_mode = result.begin();
232 while (iter_mode != result.end()) {
233 if ((*iter_mode).getModeArea() < mean_area.second) {
239 if (iter_mode != result.end()) {
240 result.insert(iter_mode, new_mode);
241 }
else if (result.size() < n) {
242 result.push_back(new_mode);
244 total_area -= mean_area.second;
245 out = result.size() >= n && (result.back().getModeArea() > total_area || loop > 3*n);
247 pdf_xy =
flatternPeak(pdf_xy, min_max.first, min_max.second, 0.0);
256 auto pdf_xy =
getXYs(pdf);