Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::src::problem Class Reference

#include <problem.h>

Inheritance diagram for ultra::src::problem:
ultra::problem

Public Types

enum class  readiness_error {
  invalid_problem , empty_training_set , insufficient_terminals , missing_functions ,
  missing_category_terminals
}

Public Member Functions

 problem ()=default
 problem (dataframe, symbol_init=def_terminal_init)
 problem (const std::filesystem::path &, const dataframe::params &={})
 problem (std::istream &, const dataframe::params &={})
 problem (ultra::problem &&, dataframe)
bool classification () const noexcept
 Just a shorthand for checking number of classes.
std::size_t categories () const noexcept
std::size_t classes () const noexcept
std::size_t variables () const noexcept
std::expected< void, readiness_error > ready () const
void setup_symbols (symbol_init=symbol_init::all)
void setup_terminals (symbol_init=def_terminal_init)
bool is_valid () const override
Public Member Functions inherited from ultra::problem
template<Symbol S, symbol_set::weight_t = symbol_set::default_weight, class ... Args>
requires std::constructible_from<S, Args...>
std::add_pointer_t< S > insert (Args &&...)
template<std::derived_from< function > F, symbol_set::weight_t W = symbol_set::default_weight, std::convertible_to< symbol::category_t > C = symbol::category_t>
std::add_pointer_t< F > insert (symbol::category_t, std::initializer_list< C >)
template<std::derived_from< function > F, symbol_set::weight_t W = symbol_set::default_weight, std::convertible_to< symbol::category_t > C = symbol::category_t>
std::add_pointer_t< F > insert (std::initializer_list< C >)

Public Attributes

multi_dataset< dataframe > data
Public Attributes inherited from ultra::problem
parameters params {}
symbol_set sset {}

Detailed Description

A specialization of the generic problem class for symbolic regression and classification problems.

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

Member Enumeration Documentation

◆ readiness_error

Enumerator
invalid_problem 

Internal consistency check failed.

empty_training_set 

No examples available for training.

insufficient_terminals 

Not enough terminals to build individuals.

missing_functions 

No functions available for evolution.

missing_category_terminals 

A used category has no terminals.

Constructor & Destructor Documentation

◆ problem() [1/5]

ultra::src::problem::problem ( )
default

New empty instance of src_problem.

Warning
The user must initialise:
  • the training dataset;
  • the complete symbol set (functions and terminals) before starting the evolution.

◆ problem() [2/5]

ultra::src::problem::problem ( dataframe d,
symbol_init init_flags = def_terminal_init )
explicit

Initialises the problem with a dataset and a specified set of symbols

Parameters
[in]dinput dataframe
[in]init_flagsinitialisation type (see symbol_init enum)

By default, terminals directly derived from the data (variables / labels) are automatically inserted; any additional terminals (ephemeral random constants, problem-specific constants...) and functions must be inserted manually.

◆ problem() [3/5]

ultra::src::problem::problem ( const std::filesystem::path & ds,
const dataframe::params & p = {} )
explicit

Initialises the problem dataset with examples loaded from a file.

Parameters
[in]dsname of the dataset file (CSV or XRFF format)
[in]padditional optional parameters (see dataframe::params structure)
Warning
Users must also specify the functions to be used.
Remarks
Terminals directly derived from the data (variables / labels) are automatically inserted. Any additional terminals (ephemeral random constants, problem specific constants...) can be inserted manually.

◆ problem() [4/5]

ultra::src::problem::problem ( std::istream & ds,
const dataframe::params & p = {} )
explicit

Initialises the problem dataset with examples loaded from a file.

Parameters
[in]dsdataset
[in]padditional optional parameters (see dataframe::params structure)
Warning
Users must also specify the functions to be used.
Remarks
Terminals directly derived from the data (variables / labels) are automatically inserted. Any additional terminals (ephemeral random constants, problem specific constants...) can be inserted manually.

◆ problem() [5/5]

ultra::src::problem::problem ( ultra::problem && base,
dataframe d )

Constructs a src::problem from an existing base problem by transferring configuration and symbol set ownership.

Parameters
[in,out]basesource problem to consume (moved-from on return)
[in]dtraining dataset for the new problem
Postcondition
  • this->params and this->sset are taken from base
  • base remains valid but its params/sset are in a moved-from state
Warning
This constructor does not prove semantic compatibility between d and the moved symbol set. The caller must ensure categories/domains are coherent.

Member Function Documentation

◆ categories()

std::size_t ultra::src::problem::categories ( ) const
nodiscardnoexcept
Returns
number of categories of the problem (>= 1)

◆ classes()

std::size_t ultra::src::problem::classes ( ) const
nodiscardnoexcept
Returns
number of classes of the problem (== 0 for a symbolic regression problem, > 1 for a classification problem)

◆ is_valid()

bool ultra::src::problem::is_valid ( ) const
nodiscardoverridevirtual
Returns
true if the object passes the internal consistency check

Reimplemented from ultra::problem.

◆ ready()

std::expected< void, problem::readiness_error > ultra::src::problem::ready ( ) const
nodiscard

Checks whether the problem can be used to start an evolutionary run.

Returns
success if the problem is ready, otherwise the first detected reason it is not ready

A problem is considered ready when:

  • a non-empty training dataset is available;
  • the symbol set contains a sufficient number of terminals.
  • the symbol set contains functions.
  • each category used by the training data has at least one terminal.

◆ setup_symbols()

void ultra::src::problem::setup_symbols ( symbol_init init_flags = symbol_init::all)

Automatically sets up the symbol set.

Parameters
[in]init_flagsinitialisation type (see symbol_init enum)

A predefined set is created, which is useful for simple problems (e.g. single category regression or classification).

Remarks
If the terminal set is not empty, it remains unchanged and init_flags are ignored. The same rule applies to the function set.
Warning
  • Data must be loaded before creating symbols, as without data it is impossible to determine, among other things, the dataset's features.
  • Multi-category tasks are supported, but the result may be suboptimal.
Examples
sonar.cc.

◆ setup_terminals()

void ultra::src::problem::setup_terminals ( symbol_init init_flags = def_terminal_init)

Initialises the terminal set according to a given initialisation type.

Parameters
[in]init_flagsinitialisation type (see symbol_init enum)
Exceptions
`std::insufficient_data`not enough data to generate a terminal set

There is a variable for each feature. The names used for variables, if not specified in the dataset, are in the X1, ... Xn form.

◆ variables()

std::size_t ultra::src::problem::variables ( ) const
nodiscardnoexcept
Returns
dimension of the input vectors (i.e. the number of variables in the problem)

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