![]() |
Ultra 0.9.4
|
#include <function.h>
Classes | |
| class | params |
Public Types | |
| using | param_data_types = std::vector<category_t> |
| using | return_type = category_t |
| Type used to describe the return category of the function. | |
| Public Types inherited from ultra::symbol | |
| enum | format { c_format , cpp_format , python_format , sup_format } |
| Supported rendering formats for symbol stringification. | |
| using | category_t = unsigned |
| using | opcode_t = unsigned |
Public Member Functions | |
| function (const std::string &, return_type, param_data_types) | |
| function (const std::string &, std::size_t) | |
| category_t | param_category (std::size_t) const noexcept |
| const param_data_types & | categories () const noexcept |
| std::size_t | arity () const noexcept |
| virtual value_t | eval (const params &) const =0 |
| virtual std::string | to_string (format=c_format) const override |
| bool | is_valid () const override |
| Public Member Functions inherited from ultra::symbol | |
| symbol (const std::string &, category_t=default_category) | |
| virtual | ~symbol ()=default |
| Virtual destructor to allow safe polymorphic deletion. | |
| category_t | category () const noexcept |
| opcode_t | opcode () const noexcept |
| const std::string & | name () const noexcept |
| void | category (category_t) noexcept |
Additional Inherited Members | |
| Static Public Attributes inherited from ultra::symbol | |
| static constexpr category_t | default_category = 0 |
| Default category assigned when typing is not used. | |
| static constexpr category_t | undefined_category |
| Sentinel value indicating that the category has not yet been assigned. | |
A callable GP symbol with one or more input parameters.
In ULTRA, a function represents a non-terminal symbol in a genetic programming "tree". Functions label internal nodes and are evaluated by recursively evaluating their arguments and combining the results.
Each function has:
Categories are used to enforce strong typing constraints during program construction, mutation, and crossover.
| using ultra::function::param_data_types = std::vector<category_t> |
Type used to describe the categories of input parameters.
The size of this container defines the arity of the function.
| ultra::function::function | ( | const std::string & | name, |
| return_type | r, | ||
| param_data_types | par ) |
Constructs a typed function.
| [in] | name | string representation of the function (e.g. "ADD", "+") |
| [in] | r | return category of the function |
| [in] | par | categories of the input parameters |
This constructor is typically used in strongly typed GP, where both argument and return categories are explicitly specified.
| ultra::function::function | ( | const std::string & | name, |
| std::size_t | n_pars ) |
Constructs an untyped function with the given arity.
| [in] | name | string representation of the function |
| [in] | n_pars | number of input parameters |
|
nodiscardnoexcept |
Returns the number of input parameters of the function.
|
nodiscardnoexcept |
Returns the list of input parameter categories.
Evaluates the function for the given parameters.
Implemented in ultra::integer::add, ultra::integer::div, ultra::integer::ife, ultra::integer::ifl, ultra::integer::ifz, ultra::integer::mod, ultra::integer::mul, ultra::integer::shl, ultra::integer::sub, ultra::real::abs, ultra::real::add, ultra::real::aq, ultra::real::cos, ultra::real::div, ultra::real::exp, ultra::real::gt, ultra::real::idiv, ultra::real::ife, ultra::real::ifl, ultra::real::ifz, ultra::real::length, ultra::real::ln, ultra::real::lt, ultra::real::max, ultra::real::mod, ultra::real::mul, ultra::real::sigmoid, ultra::real::sin, ultra::real::sqrt, ultra::real::sub, and ultra::str::ife.
|
nodiscardoverridevirtual |
Performs an internal consistency check.
Reimplemented from ultra::symbol.
|
nodiscardnoexcept |
Returns the category of a specific input parameter.
| [in] | i | index of the input parameter |
|
nodiscardoverridevirtual |
Returns a string representation of the function.
Implements ultra::symbol.
Reimplemented in ultra::integer::add, ultra::integer::div, ultra::integer::ife, ultra::integer::ifl, ultra::integer::ifz, ultra::integer::mod, ultra::integer::mul, ultra::integer::shl, ultra::integer::sub, ultra::real::abs, ultra::real::add, ultra::real::aq, ultra::real::cos, ultra::real::div, ultra::real::exp, ultra::real::gt, ultra::real::idiv, ultra::real::ife, ultra::real::ifl, ultra::real::ifz, ultra::real::length, ultra::real::ln, ultra::real::lt, ultra::real::max, ultra::real::mod, ultra::real::mul, ultra::real::sigmoid, ultra::real::sin, ultra::real::sqrt, ultra::real::sub, and ultra::str::ife.