Родитель
8cfd8f2d8b
Сommit
06477600af
@ -1,51 +1,45 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
|
|
||||||
vector <size_t>
|
vector<size_t> make_histogram(const vector<double> &numbers, size_t bin_count) {
|
||||||
make_histogram(const vector<double>& numbers, size_t & bin_count, size_t & number_count, size_t & max_count) {
|
|
||||||
double min, max;
|
double min, max;
|
||||||
find_minmax(numbers, min, max);
|
bool res = false;
|
||||||
|
find_minmax(numbers, min, max, res);
|
||||||
double bin_size = ( max - min ) / bin_count;
|
double bin_size = ( max - min ) / bin_count;
|
||||||
vector<size_t> bins ( bin_count );
|
vector<size_t> bins ( bin_count );
|
||||||
max_count = bins[0];
|
for (size_t i=0; i < numbers.size(); i++ ){
|
||||||
for (size_t i = 0; i < number_count; i++){
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
for (size_t j = 0; ( j < bin_count - 1 ) && !found; j++ ){
|
for (size_t j = 0; ( j < bin_count - 1 ) && !found; j++ ){
|
||||||
auto lo = min + j * bin_size;
|
auto lo = min + j * bin_size;
|
||||||
auto hi = min + ( j + 1 ) * bin_size;
|
auto hi = min + ( j + 1 ) * bin_size;
|
||||||
if ((lo <= numbers[i]) && (numbers[i] < hi)){
|
if (lo <= numbers[i] && ( numbers[i] < hi )){
|
||||||
bins[j]++;
|
bins[j]++;
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (bins[j] > max_count){
|
|
||||||
max_count = bins[j];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( !found ){
|
if ( !found ){
|
||||||
bins[bin_count-1]++;
|
bins[bin_count-1]++;
|
||||||
}
|
}
|
||||||
if (bins[bin_count - 1] > max_count){
|
|
||||||
max_count = bins[bin_count - 1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
find_minmax(const vector <double> &numbers, double &min, double &max, bool &res) {
|
||||||
if (!numbers.empty()) {
|
|
||||||
|
if (numbers.size()==0){
|
||||||
|
res = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
} else {
|
for ( double x : numbers ){
|
||||||
min = 0;
|
|
||||||
max = 0;
|
|
||||||
}
|
|
||||||
for (double x : numbers)
|
|
||||||
{
|
|
||||||
if ( x < min ){
|
if ( x < min ){
|
||||||
min = x;
|
min = x;
|
||||||
}
|
} else if ( x > max ){
|
||||||
else if (x > max){
|
|
||||||
max = x;
|
max = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
Ссылка в новой задаче