-
Notifications
You must be signed in to change notification settings - Fork 3
/
stat_progress.hpp
70 lines (55 loc) · 2.33 KB
/
stat_progress.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef CVT_MAP_ELITES_STAT_MAP_PROGRESS_HPP_
#define CVT_MAP_ELITES_STAT_MAP_PROGRESS_HPP_
#include <boost/multi_array.hpp>
#include <numeric>
#include <sferes/stat/stat.hpp>
namespace sferes {
namespace stat {
SFERES_STAT(MapProgress, Stat)
{
public:
typedef boost::shared_ptr<Phen> phen_t;
typedef boost::array<float, Params::ea::number_of_dimensions> point_t;
size_t number_of_dimensions;
MapProgress() : number_of_dimensions(Params::ea::number_of_dimensions) {}
template <typename E>
void refresh(const E& ea)
{
this->_create_log_file(ea, "progress_archive.dat");
_write_progress(ea, *this->_log_file);
}
template <class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar& BOOST_SERIALIZATION_NVP(number_of_dimensions);
}
protected:
template <typename EA>
void _write_progress(const EA& ea, std::ofstream& ofs) const
{
double archive_min = std::numeric_limits<double>::max();
double archive_max = std::numeric_limits<double>::lowest();
double archive_mean = 0.0;
size_t archive_size = 0;
std::vector<phen_t> archive = ea.archive();
for (size_t i = 0; i < archive.size(); ++i) {
if (archive[i]) {
archive_size++;
archive_mean += archive[i]->fit().value();
if (archive[i]->fit().value() < archive_min)
archive_min = archive[i]->fit().value();
if (archive[i]->fit().value() > archive_max)
archive_max = archive[i]->fit().value();
}
}
// dividing by archive_size might be problematic if it is =0
if (archive_size > 0)
archive_mean /= archive_size;
ofs << ea.gen() << " " << ea.nb_evals() << " " << archive_size << " "
<< archive_min << " " << archive_mean << " " << archive_max
<< std::endl;
}
};
} // namespace stat
} // namespace sferes
#endif