Find highest value over multiple bins in histogram

This commit is contained in:
Sebastian Piwell
2016-06-10 15:36:36 -04:00
parent 39f083c342
commit 157ca752b2
2 changed files with 27 additions and 3 deletions

View File

@@ -71,7 +71,7 @@ public:
float equalize (float);
float entropy();
float highestBinValue(bool equalized);
float highestBinValue(bool equalized, int overBins=0);
float binWidth();
void changeRange(float minValue, float maxValue);

View File

@@ -307,17 +307,41 @@ void Histogram::print() const {
std::cout << std::endl << std::endl << std::endl<< "==============" << std::endl;
}
float Histogram::highestBinValue(bool equalized){
float Histogram::highestBinValue(bool equalized, int overBins){
int highestBin = 0;
float highestValue = 0;
for(int i=0; i<_numBins; i++){
if(_data[i] > _data[highestBin])
float value = 0;
int num = 0;
for(int j=0; j<overBins; j++){
if(i-j>0){
value += _data[i-j];
num++;
}
if(i+j<_numBins){
value += _data[i+j];
num++;
}
}
value += _data[i];
value /= (float)++num;
if(value > highestValue){
highestBin = i;
highestValue = value;
}
// if(_data[i] > _data[highestBin])
// highestBin = i;
}
float low = _minValue + float(highestBin) / _numBins * (_maxValue - _minValue);
float high = low + (_maxValue - _minValue) / float(_numBins);
if(!equalized){
std::cout << (high+low)/2.0 << std::endl;
return (high+low)/2.0;
}else{
return equalize((high+low)/2.0);