Commit a319729c authored by Sylvain Thery's avatar Sylvain Thery
Browse files

Bug in height of quantile for histo superposition

parent 99f83d7e
...@@ -168,9 +168,11 @@ class Histogram ...@@ -168,9 +168,11 @@ class Histogram
/// get idx of data in attribute /// get idx of data in attribute
unsigned int idx(unsigned int i) const; unsigned int idx(unsigned int i) const;
// comparison function for sorting data /// comparison function for sorting data
static bool dataComp( const std::pair<double, unsigned int>& a, const std::pair<double, unsigned int>& b); static bool dataComp( const std::pair<double, unsigned int>& a, const std::pair<double, unsigned int>& b);
/// update quantiles height from histo area for correct superposition
void quantilesAreaCorrection();
public: public:
/** /**
...@@ -178,7 +180,6 @@ public: ...@@ -178,7 +180,6 @@ public:
*/ */
Histogram(HistoColorMap& hcm); Histogram(HistoColorMap& hcm);
/** /**
* init data * init data
* @param conv a attribute convertor * @param conv a attribute convertor
...@@ -348,7 +349,6 @@ public: ...@@ -348,7 +349,6 @@ public:
*/ */
const HistoColorMap& colorMap() const; const HistoColorMap& colorMap() const;
}; };
......
...@@ -87,6 +87,11 @@ void Histogram::populateHisto(unsigned int nbclasses) ...@@ -87,6 +87,11 @@ void Histogram::populateHisto(unsigned int nbclasses)
if (m_populations[i] > m_maxBar) if (m_populations[i] > m_maxBar)
m_maxBar = m_populations[i]; m_maxBar = m_populations[i];
} }
// apply area correction on quantile if necessary
if (m_pop_quantiles.size() != 0 )
quantilesAreaCorrection();
} }
void Histogram::populateQuantiles(unsigned int nbquantiles) void Histogram::populateQuantiles(unsigned int nbquantiles)
...@@ -121,21 +126,30 @@ void Histogram::populateQuantiles(unsigned int nbquantiles) ...@@ -121,21 +126,30 @@ void Histogram::populateQuantiles(unsigned int nbquantiles)
val = m_dataIdx.back().first; val = m_dataIdx.back().first;
m_interv.push_back(val); m_interv.push_back(val);
} }
quantilesAreaCorrection();
}
m_maxQBar = 0.0;
// constant area correction void Histogram::quantilesAreaCorrection()
double lc = 1.0f; {
unsigned int nbquantiles = m_pop_quantiles.size();
if (m_nbclasses != 0) //for histo superposition // constant area correction
lc = double(m_dataIdx.back().first - m_dataIdx.front().first )/double(m_nbclasses); double areaQ1 = 100.0f; // use 100 as area if no histogram
if (m_nbclasses!=0)
{
double areaH = (getMax()-getMin())/double(m_nbclasses) * double(m_dataIdx.size());
areaQ1 = areaH/nbquantiles; // area of one quantile
}
m_maxQBar = 0.0;
for (unsigned int i = 0; i < nbquantiles; ++i) for (unsigned int i = 0; i < nbquantiles; ++i)
{ {
double lq = m_interv[i+1] - m_interv[i]; // compute height instead of population
m_pop_quantiles[i] = m_pop_quantiles[i]*lc/lq; double lq = m_interv[i+1] - m_interv[i]; // width
m_pop_quantiles[i] = areaQ1/lq; // height = area / width
if (m_pop_quantiles[i] > m_maxQBar) if (m_pop_quantiles[i] > m_maxQBar)
m_maxQBar = m_pop_quantiles[i]; m_maxQBar = m_pop_quantiles[i]; // store max
} }
} }
...@@ -202,8 +216,6 @@ unsigned int Histogram::cellsOfQuantilesColumn( unsigned int c, std::vector<unsi ...@@ -202,8 +216,6 @@ unsigned int Histogram::cellsOfQuantilesColumn( unsigned int c, std::vector<unsi
} }
} }
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment