Vita
search.h
Go to the documentation of this file.
1
13#if !defined(VITA_SEARCH_H)
14#define VITA_SEARCH_H
15
16#include "kernel/evolution.h"
17#include "kernel/problem.h"
19
20namespace vita
21{
22
23template<class T>
25{
26 void update(const summary<T> &);
27
28 summary<T> overall = {};
30 std::set<unsigned> good_runs = {};
31
32 unsigned best_run = 0;
33 unsigned runs = 0;
34};
35
52template<class T, template<class> class ES = vita::std_es>
53class search
54{
55public:
56 explicit search(problem &);
57
58 summary<T> run(unsigned = 1);
59
60 template<class E, class... Args> search &training_evaluator(Args && ...);
61 template<class E, class... Args> search &validation_evaluator(Args && ...);
62
63 template<class V, class... Args> search &validation_strategy(Args && ...);
64
65 search &after_generation(
66 typename evolution<T, ES>::after_generation_callback_t);
67
68 virtual bool is_valid() const;
69
70protected:
71 // Template method of the search::run() member function called at the end of
72 // each run.
73 virtual void after_evolution(const summary<T> &);
74
75 virtual void calculate_metrics(summary<T> *) const;
76
77 // Returns `true` when a validation criterion is available: i.e. it needs
78 // that `eva2_` is set. Derived classes can add further requirements.
79 virtual bool can_validate() const;
80
81 // Template method of the search::run() member function called exactly one
82 // time at the end of the last run.
83 virtual void close();
84
85 // Template method of the search::run() member function called exactly one
86 // time just before the first run.
87 virtual void init();
88
89 // Template method of the search::run() member function called at the end of
90 // each run. Logs search statistics.
91 virtual void log_stats(const search_stats<T> &,
92 tinyxml2::XMLDocument *) const;
93
94 // Template method of the search::after_evolution member function.
95 virtual void print_resume(const model_measurements &) const;
96
97 virtual void tune_parameters();
98
99 // *** Data members ***
100 std::unique_ptr<evaluator<T>> eva1_; // fitness function for training
101 std::unique_ptr<evaluator<T>> eva2_; // fitness function for validation
102 std::unique_ptr<vita::validation_strategy> vs_;
103
104 // Problem we're working on.
105 problem &prob_;
106
107 // Callback functions.
108 typename evolution<T, ES>::after_generation_callback_t
109 after_generation_callback_;
110
111private:
112 void log_stats(const search_stats<T> &) const;
113 bool load();
114 bool save() const;
115};
116
117#include "kernel/search.tcc"
118} // namespace vita
119
120#endif // include guard
Simplifies the calculation of statistics regarding a sequence (mean, variance, standard deviation,...
Definition: distribution.h:31
Aggregates the problem-related data needed by an evolutionary program.
Definition: problem.h:24
Search drives the evolution.
Definition: search.h:54
Standard evolution strategy.
A summary of evolution (results, statistics...).
Interface for specific training / cross validation techniques (e.g.
The main namespace for the project.
A collection of measurements.
unsigned runs
index of the run giving the best solution
Definition: search.h:33