verify that pop is not empty before attempting to compute the IQR
This commit is contained in:
parent
327d9363af
commit
fb8a8d79fd
1 changed files with 14 additions and 9 deletions
|
|
@ -38,7 +38,7 @@ Contact: http://eodev.sourceforge.net
|
|||
#include <utils/eoParam.h>
|
||||
#include <eoPop.h>
|
||||
#include <utils/eoMonitor.h>
|
||||
#include <utils/eoCheckPoint.h>
|
||||
//#include <utils/eoCheckPoint.h>
|
||||
|
||||
/** @defgroup Stats Statistics computation
|
||||
*
|
||||
|
|
@ -435,16 +435,21 @@ public:
|
|||
|
||||
virtual void operator()( const eoPop<EOT> & _pop )
|
||||
{
|
||||
eoPop<EOT> pop = _pop;
|
||||
if( _pop.size() == 0 ) {
|
||||
// how to implement value() = 0 ?
|
||||
|
||||
unsigned int quartile = pop.size()/4;
|
||||
std::nth_element( pop.begin(), pop.begin()+quartile*1, pop.end() );
|
||||
typename EOT::Fitness Q1 = pop[quartile].fitness();
|
||||
|
||||
std::nth_element( pop.begin(), pop.begin()+quartile*3, pop.end() );
|
||||
typename EOT::Fitness Q3 = pop[quartile*3].fitness();
|
||||
} else {
|
||||
eoPop<EOT> pop = _pop;
|
||||
|
||||
value() = Q1 - Q3;
|
||||
unsigned int quartile = pop.size()/4;
|
||||
std::nth_element( pop.begin(), pop.begin()+quartile*1, pop.end() );
|
||||
typename EOT::Fitness Q1 = pop[quartile].fitness();
|
||||
|
||||
std::nth_element( pop.begin(), pop.begin()+quartile*3, pop.end() );
|
||||
typename EOT::Fitness Q3 = pop[quartile*3].fitness();
|
||||
|
||||
value() = Q1 - Q3;
|
||||
}
|
||||
}
|
||||
|
||||
virtual std::string className(void) const { return "eoInterquartileRangeStat"; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue