Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::src::search< P > Class Template Reference

#include <search.h>

Public Types

using individual_t = P
using fitness_t = double
using after_generation_callback_t
using on_training_new_best_callback_t
using class_evaluator_t = gaussian_evaluator<P>
using reg_evaluator_t = rmae_evaluator<P>

Public Member Functions

 search (problem &, metric_flags=metric_flags::accuracy)
search_stats< P, fitness_t > run (unsigned=1, const model_measurements< fitness_t > &={})
std::unique_ptr< basic_oracle > predictor (const P &) const
search & after_generation (after_generation_callback_t)
search & logger (search_log &)
search & messages (bool) noexcept
search & on_training_new_best (on_training_new_best_callback_t)
template<class F>
search & refinement (F &&)
search & stop_source (std::stop_source)
search & tag (const std::string &)
template<ValidationStrategy, class... Args>
search & validation_strategy (Args &&...)
template<class F>
search< P > & refinement (F &&f)
template<ValidationStrategy V, class... Args>
search< P > & validation_strategy (Args &&...args)
template<class F>
search< P > & refinement (F &&f)
template<ValidationStrategy V, class... Args>
search< P > & validation_strategy (Args &&...args)

Detailed Description

template<Individual P>
class ultra::src::search< P >

Thin facade over the concrete classification or regression search engine.

The engine kind is selected at construction time from the problem type. Configuration calls are forwarded directly to the selected engine.

Examples
sonar.cc, symbolic_regression.cc, symbolic_regression01.cc, and symbolic_regression02.cc.

Member Typedef Documentation

◆ after_generation_callback_t

template<Individual P>
using ultra::src::search< P >::after_generation_callback_t
Initial value:
ultra::after_generation_callback_t<P, fitness_t>

◆ on_training_new_best_callback_t

template<Individual P>
using ultra::src::search< P >::on_training_new_best_callback_t
Initial value:
ultra::on_new_best_callback_t<P, fitness_t>

Member Function Documentation

◆ after_generation()

template<Individual P>
search< P > & search::after_generation ( after_generation_callback_t f)

Sets a callback function executed at the end of every generation.

Parameters
[in]fcallback function
Returns
a reference to this object (method chaining / fluent interface)
Examples
symbolic_regression02.cc.

◆ logger()

template<Individual P>
search< P > & search::logger ( search_log & sl)

Sets the search/evolution logger.

Parameters
[in]sllogger
Returns
a reference to this object (method chaining / fluent interface)
Remarks
Logger must be set before calling run. By default, data logging is disabled.

◆ on_training_new_best()

template<Individual P>
search< P > & search::on_training_new_best ( on_training_new_best_callback_t f)

Hook invoked whenever the evolution discovers a new training-set best.

Parameters
[in]fcallback function
Returns
a reference to this object (method chaining / fluent interface)

◆ predictor()

template<Individual P>
std::unique_ptr< basic_oracle > search::predictor ( const P & prg) const
nodiscard

Creates a runtime-polymorphic predictor associated with a given individual.

Parameters
[in]prgindividual used as building block for the predictor
Returns
a dynamically allocated predictor or nullptr if the active evaluator does not provide one

This function provides a uniform interface over different evaluator types. If the selected evaluator exposes a predictor() method, its result is wrapped into a std::unique_ptr<basic_oracle>. Otherwise nullptr is returned.

Note
Predictor availability is detected at compile time and mapped to a runtime polymorphic interface.

◆ refinement() [1/2]

template<Individual P>
template<class F>
search< P > & ultra::src::search< P >::refinement ( F && f)

Sets a refinement callback used to locally improve individuals.

Parameters
[in]fcallable object implementing the refinement logic
Returns
a reference to *this object (method chaining / fluent interface)

The refinement callback is invoked during the evolutionary process to perform local optimisation (e.g. numerical tuning of parameters) on candidate solutions.

The callable must have a signature compatible with at least one of the following forms:

std::optional<fitness_t>(
std::optional<fitness_t>(
Definition evaluator_proxy.h:45
Parameters controlling numerical optimisation of GP individuals.
Definition parameters.h:203

A generic callable can be used to support both cases:

[](P &ind, const auto &eva,
{
// eva is the evaluator proxy used by the search engine
// (includes caching and other internal mechanisms)
return std::optional<fitness_t>();
}

The evaluator passed to the callback is the same object used internally by the evolutionary engine (i.e. an evaluator_proxy), ensuring that refinement benefits from cached evaluations and consistent semantics.

Note
The concrete evaluator type depends on the problem (classification or regression) and is selected automatically at runtime. An evaluator-specific callable that does not match the selected evaluator disables refinement.

◆ refinement() [2/2]

template<Individual P>
template<class F>
search< P > & ultra::src::search< P >::refinement ( F && f)

Sets a refinement callback used to locally improve individuals.

Parameters
[in]fcallable object implementing the refinement logic
Returns
a reference to *this object (method chaining / fluent interface)

The refinement callback is invoked during the evolutionary process to perform local optimisation (e.g. numerical tuning of parameters) on candidate solutions.

The callable must have a signature compatible with at least one of the following forms:

std::optional<fitness_t>(
std::optional<fitness_t>(

A generic callable can be used to support both cases:

[](P &ind, const auto &eva,
{
// eva is the evaluator proxy used by the search engine
// (includes caching and other internal mechanisms)
return std::optional<fitness_t>();
}

The evaluator passed to the callback is the same object used internally by the evolutionary engine (i.e. an evaluator_proxy), ensuring that refinement benefits from cached evaluations and consistent semantics.

Note
The concrete evaluator type depends on the problem (classification or regression) and is selected automatically at runtime. An evaluator-specific callable that does not match the selected evaluator disables refinement.

◆ stop_source()

template<Individual P>
search< P > & search::stop_source ( std::stop_source ss)

Set a stop source for performing cooperative task shutdown.

Parameters
[in]ssstop source to issue a stop request
Returns
a reference to this object (method chaining / fluent interface)

◆ tag()

template<Individual P>
search< P > & search::tag ( const std::string & t)

Sets the identification tag for this object.

Parameters
[in]tidentification tag
Returns
a reference to this object (method chaining / fluent interface)

The tag is used to identify this object when multiple searches are performed in parallel.

◆ validation_strategy() [1/2]

template<Individual P>
template<ValidationStrategy V, class... Args>
search< P > & ultra::src::search< P >::validation_strategy ( Args &&... args)

Builds and sets the active validation strategy.

Parameters
[in]argsparameters for the validation strategy
Returns
reference to the search class (used for method chaining)

◆ validation_strategy() [2/2]

template<Individual P>
template<ValidationStrategy V, class... Args>
search< P > & ultra::src::search< P >::validation_strategy ( Args &&... args)

Builds and sets the active validation strategy.

Parameters
[in]argsparameters for the validation strategy
Returns
reference to the search class (used for method chaining)

The documentation for this class was generated from the following files: