Vita
analyzer.h
Go to the documentation of this file.
1
13#if !defined(VITA_ANALYZER_H)
14#define VITA_ANALYZER_H
15
16#include <map>
17
18#include "kernel/distribution.h"
19#include "kernel/ga/i_de.h"
20#include "kernel/ga/i_ga.h"
21#include "kernel/gp/symbol.h"
22
23namespace vita
24{
25
42template<class T>
44{
45public:
47 {
50 std::uintmax_t counter[2] = {0, 0};
51 };
52
53 analyzer();
54
55 void add(const T &, const fitness_t &, unsigned = 0);
56
57 void clear();
58
59 std::uintmax_t functions(bool) const;
60 std::uintmax_t terminals(bool) const;
61
62 const distribution<double> &age_dist() const;
63 const distribution<fitness_t> &fit_dist() const;
64 const distribution<double> &length_dist() const;
65
66 const distribution<double> &age_dist(unsigned) const;
67 const distribution<fitness_t> &fit_dist(unsigned) const;
68
72 typename std::map<const symbol *, sym_counter>::const_iterator;
73
74 const_iterator begin() const;
75 const_iterator end() const;
76
77 bool is_valid() const;
78
79private:
80 void count(const symbol *, bool);
81 std::size_t count(const T &);
82 std::size_t count_team(const T &, std::true_type);
83 template<class U> std::size_t count_team(const U &, std::false_type);
84 template<class U> std::size_t count_introns(const U &, std::true_type);
85 template<class U> std::size_t count_introns(const U &, std::false_type);
86
87 // This comparator is useful for debugging purpose: when we insert a
88 // symbol pointer in an ordered container, it induces a well defined
89 // order. Without this the default comparison for pointers has a
90 // unspecified (and not necessarily stable & consistent) behaviour.
91 // Well defined order means a simple way of debugging statistics.
92 struct cmp_symbol_ptr
93 {
94 bool operator()(const symbol *a, const symbol *b) const
95 { return a->opcode() < b->opcode(); }
96 };
97 std::map<const symbol *, sym_counter, cmp_symbol_ptr> sym_counter_;
98
99 struct group_stat
100 {
101 distribution<double> age;
102 distribution<fitness_t> fitness;
103 };
104 std::map<unsigned, group_stat> group_stat_;
105
106 distribution<fitness_t> fit_;
107 distribution<double> age_;
108 distribution<double> length_;
109
110 sym_counter functions_;
111 sym_counter terminals_;
112}; // analyzer
113
114#include "kernel/analyzer.tcc"
115} // namespace vita
116
117#endif // include guard
Analyzer takes a statistics snapshot of a population.
Definition: analyzer.h:44
typename std::map< const symbol *, sym_counter >::const_iterator const_iterator
Type returned by begin() and end() methods to iterate through the statistics of the various symbols.
Definition: analyzer.h:72
Together functions and terminals are referred to as symbols.
Definition: symbol.h:36
opcode_t opcode() const
An opcode is a unique, numerical session ID for a symbol.
Definition: symbol.h:145
The main namespace for the project.
std::uintmax_t counter[2]
Typical use: counter[active] or counter[!active] (where active is a boolean).
Definition: analyzer.h:50