From cf5533c1b288ceb94caacc13eee3f7952369ae88 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Mon, 8 Nov 2010 18:29:25 +0100 Subject: [PATCH] new eoAerageSizeStat class --- eo/NEWS | 1 + eo/src/utils/eoStat.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/eo/NEWS b/eo/NEWS index 359668933..50e256087 100644 --- a/eo/NEWS +++ b/eo/NEWS @@ -15,6 +15,7 @@ - dual fitness class to handle feasibility of individual with guarantee that feasible fitness will always be better than unfeasible one - feasible fitness ratio stat - interquartile range stat + - average size of individuals stat - uniform(min,max) random function - compatibility macros for compiling paradiseo with CUDACC - removed old multi-objective classes, deprecated by the Paradiseo-MOEO project diff --git a/eo/src/utils/eoStat.h b/eo/src/utils/eoStat.h index d27520b13..b4e8c4592 100644 --- a/eo/src/utils/eoStat.h +++ b/eo/src/utils/eoStat.h @@ -423,6 +423,7 @@ public : }; */ + //! A robust measure of dispersion (also called midspread or middle fifty) that is the difference between the third and the first quartile. template class eoInterquartileRangeStat : public eoStat< EOT, typename EOT::Fitness > @@ -449,6 +450,41 @@ public: virtual std::string className(void) const { return "eoInterquartileRangeStat"; } }; + +/** Compute the average size of indivudals over the population + * + * Obviously, will work only on representations that implement the (standard) "size()" method, + * like any STL container. + */ +template +class eoAverageSizeStat : public eoStat< EOT, double> +{ +public: + + using eoStat::value; + + eoAverageSizeStat( std::string description = "Av.Size" ) : + eoStat( 0.0, description ) {} // 0 by default + + virtual void operator()( const eoPop & pop ) + { + size_t pop_size = pop.size(); + + std::vector sizes; + sizes.reserve(pop_size); + + for( unsigned int i=0, s = pop_size; i(sum) / static_cast(pop_size); + } + + virtual std::string className(void) const { return "eoAverageSizeStat"; } +}; + /** @} */ #endif