![]() |
Ultra 0.9.4
|
#include <search.h>
Public Types | |
| using | individual_t = evaluator_individual_t<E> |
| using | fitness_t = evaluator_fitness_t<E> |
| using | after_generation_callback_t |
| using | refinement_callback_t |
| using | on_training_new_best_callback_t |
Public Member Functions | |
| basic_search (problem &, E) | |
| search_stats< individual_t, fitness_t > | run (unsigned=1, const model_measurements< fitness_t > &={}) |
| basic_search & | after_generation (after_generation_callback_t) |
| basic_search & | logger (search_log &) noexcept |
| basic_search & | refinement (refinement_callback_t) |
| basic_search & | on_training_new_best (on_training_new_best_callback_t) |
| basic_search & | messages (bool) noexcept |
| basic_search & | tag (const std::string &) |
| basic_search & | stop_source (std::stop_source) |
| template<ValidationStrategy, class... Args> | |
| basic_search & | validation_strategy (Args &&...) |
| basic_search & | validation_strategy (const ultra::validation_strategy &) |
| virtual bool | is_valid () const |
| template<ValidationStrategy V, class... Args> | |
| basic_search< ES, E > & | validation_strategy (Args &&...args) |
| template<ValidationStrategy V, class... Args> | |
| basic_search< ES, E > & | validation_strategy (Args &&...args) |
| template<template< class > class ES, Evaluator E> | |
| basic_search< ES, E > & | validation_strategy (const ultra::validation_strategy &vs) |
Protected Member Functions | |
| virtual void | after_evolution (unsigned, const std::vector< model_measurements< fitness_t > > &) |
| virtual model_measurements< fitness_t > | calculate_metrics (const individual_t &) const |
| virtual void | tune_parameters () |
Protected Attributes | |
| evaluator_proxy< E > | eva_ |
| std::unique_ptr< ultra::validation_strategy > | vs_ {std::make_unique<as_is_validation>()} |
| problem & | prob_ |
| after_generation_callback_t | after_generation_callback_ {} |
| refinement_callback_t | refinement_callback_ {} |
| on_training_new_best_callback_t | on_training_new_best_callback_ {} |
basic_search drives the evolution.
The class offers a general / customizable search strategy.
| using ultra::basic_search< ES, E >::after_generation_callback_t |
| using ultra::basic_search< ES, E >::on_training_new_best_callback_t |
| using ultra::basic_search< ES, E >::refinement_callback_t |
| basic_search::basic_search | ( | problem & | prob, |
| E | eva ) |
| [in] | prob | the problem we're working on. The lifetime of prob must exceed lifetime of this class |
| [in] | eva | evaluator used during evolution to build the evaluator proxy |
|
protectedvirtual |
Template method of the run member function called at the end of each run.
| [in] | run | current run |
| [in] | mm | measurements related to the best program of the current run (training set measurements and possibly validation set) |
| basic_search< ES, E > & basic_search::after_generation | ( | after_generation_callback_t | f | ) |
Sets a callback function executed at the end of every generation.
| [in] | f | callback function |
|
nodiscardprotectedvirtual |
Calculates and stores the fitness of the best individual so far.
| [in] | prg | best individual from the evolution run just finished |
Specializations of this method can calculate further / distinct problem-specific metrics regarding the candidate solution.
If a validation set / simulation is available, it's used for the calculations.
Reimplemented in ultra::src::basic_search< ES, E >, ultra::src::basic_search< alps_es, class_evaluator_t >, and ultra::src::basic_search< alps_es, reg_evaluator_t >.
|
nodiscardvirtual |
Reimplemented in ultra::src::basic_search< ES, E >, ultra::src::basic_search< alps_es, class_evaluator_t >, and ultra::src::basic_search< alps_es, reg_evaluator_t >.
|
noexcept |
Sets the search/evolution logger.
| [in] | sl | logger |
| basic_search< ES, E > & basic_search::on_training_new_best | ( | on_training_new_best_callback_t | f | ) |
Hook invoked whenever the evolution discovers a new training-set best.
| [in] | f | callback function |
| search_stats< typename basic_search< ES, E >::individual_t, typename basic_search< ES, E >::fitness_t > basic_search::run | ( | unsigned | n = 1, |
| const model_measurements< fitness_t > & | threshold = {} ) |
Executes a given number of evolutionary-runs possibly saving good runs.
| [in] | n | number of runs |
| [in] | threshold | used to identify successfully learned (matched, classified, resolved...) examples |
| basic_search< ES, E > & basic_search::stop_source | ( | std::stop_source | ss | ) |
Set a stop source for performing cooperative task shutdown.
| [in] | ss | stop source to issue a stop request |
| basic_search< ES, E > & basic_search::tag | ( | const std::string & | t | ) |
Sets the identification tag for this object.
| [in] | t | identification tag |
The tag is used to identify this object when multiple searches are performed in parallel.
|
protectedvirtual |
Tries to tune search parameters for the current problem.
Parameter tuning is a typical approach to algorithm design. Such tuning is done by experimenting with different values and selecting the ones that give the best results on the test problems at hand.
However, the number of possible parameters and their different values means that this is a very complex and time-consuming task; it is something we do not want users to worry about (power users can force many parameters, but our idea is "simple by default").
So if user sets an environment parameter he will force the search class to use it as is. Otherwise this function will try to guess a good starting point and changes its hint after every run. The code is a mix of black magic, experience, common logic and randomness but it seems reasonable.
Tries to tune search parameters for the current problem.
General scheme:
Reimplemented in ultra::de::search< E >, ultra::ga::search< E >, ultra::hga::search< E >, ultra::src::basic_search< ES, E >, ultra::src::basic_search< alps_es, class_evaluator_t >, and ultra::src::basic_search< alps_es, reg_evaluator_t >.
| basic_search< ES, E > & ultra::basic_search< ES, E >::validation_strategy | ( | Args &&... | args | ) |
Builds and sets the active validation strategy.
| [in] | args | parameters for the validation strategy |
| basic_search< ES, E > & ultra::basic_search< ES, E >::validation_strategy | ( | Args &&... | args | ) |
Builds and sets the active validation strategy.
| [in] | args | parameters for the validation strategy |
| basic_search< ES, E > & ultra::basic_search< ES, E >::validation_strategy | ( | const ultra::validation_strategy & | vs | ) |
Sets the active validation strategy.
| [in] | vs | a validation strategy |
| basic_search< ES, E > & ultra::basic_search< ES, E >::validation_strategy | ( | const ultra::validation_strategy & | vs | ) |
Sets the active validation strategy.
| [in] | vs | a validation strategy |