Vita
Public Member Functions | Static Public Member Functions | List of all members
vita::function Class Reference

A symbol with arity() > 0. More...

#include <function.h>

Inherits vita::symbol.

Inherited by vita::boolean::l_and, vita::boolean::l_not, vita::boolean::l_or, vita::integer::add, vita::integer::div, vita::integer::ife, vita::integer::ifl, vita::integer::ifz, vita::integer::mod, vita::integer::mul, vita::integer::shl, vita::integer::sub, vita::real::abs, vita::real::add, vita::real::aq, vita::real::cos, vita::real::div, vita::real::gt, vita::real::idiv, vita::real::ifb, vita::real::ife, vita::real::ifl, vita::real::ifz, vita::real::length, vita::real::ln, vita::real::lt, vita::real::max, vita::real::mod, vita::real::mul, vita::real::sigmoid, vita::real::sin, vita::real::sqrt, vita::real::sub, and vita::str::ife.

Public Member Functions

category_t arg_category (std::size_t) const
 
unsigned arity () const final
 
virtual bool associative () const
 Is the symbol subject to the associative law of arithmetic? More...
 
virtual std::string display (format=c_format) const
 
 function (const std::string &, category_t, cvect)
 
 function (const std::string &, std::size_t)
 
bool is_valid () const override
 
- Public Member Functions inherited from vita::symbol
virtual unsigned arity () const =0
 
category_t category () const
 The type (a.k.a. More...
 
void category (category_t)
 Changes the category of a symbol. More...
 
virtual value_t eval (symbol_params &) const =0
 Calculates the value of / performs the action associated with the symbol (it's implementation specific). More...
 
virtual bool input () const
 An input variable is a feature from the learning domain. More...
 
virtual bool is_valid () const
 
std::string name () const
 
opcode_t opcode () const
 An opcode is a unique, numerical session ID for a symbol. More...
 
double penalty (core_interpreter *) const
 Used for automatic calculation of penalities due to broken constraints. More...
 
 symbol (const std::string &, category_t=0)
 
bool terminal () const
 

Static Public Member Functions

static const functioncast (const symbol *)
 This is a short cut function. More...
 

Additional Inherited Members

- Public Types inherited from vita::symbol
enum  format {
  c_format , cpp_format , mql_format , python_format ,
  sup_format
}
 Symbol rendering format. More...
 

Detailed Description

A symbol with arity() > 0.

A function labels the internal (non-leaf) points of the parse trees that represent the programs in the population. An example function set might be {+, -, *}.

Warning
Each function should be able to handle gracefully all values it might receive as input (this is called closure property). If there is a way to crash the system, the GP system will certainly hit upon hit.

Definition at line 34 of file function.h.

Constructor & Destructor Documentation

◆ function() [1/2]

vita::function::function ( const std::string &  dis,
category_t  c,
cvect  args 
)
Parameters
[in]disstring representation of the function (e.g. for the plus function it could by "ADD" or "+")
[in]ccategory of the function (i.e. the category of the output value)
[in]argsinput parameters (type and number) of the function (in C++ they are called the "function signature")

Definition at line 25 of file function.cc.

◆ function() [2/2]

vita::function::function ( const std::string &  dis,
std::size_t  n_args 
)
Parameters
[in]disstring representation of the function (e.g. for the plus function it could by "ADD" or "+")
[in]n_argsnumber of arguments of the function

Assumes category 0 for the function and its arguments. This constructor is usually chosen when types are not used.

Definition at line 39 of file function.cc.

Member Function Documentation

◆ arg_category()

category_t vita::function::arg_category ( std::size_t  i) const
inline
Parameters
[in]iindex of a function argument
Returns
category of the i-th function argument

Definition at line 89 of file function.h.

◆ arity()

unsigned vita::function::arity ( ) const
inlinefinalvirtual
Returns
the number arguments of a funtion

Implements vita::symbol.

Definition at line 59 of file function.h.

◆ associative()

bool vita::function::associative ( ) const
inlinevirtual

Is the symbol subject to the associative law of arithmetic?

Returns
true if the function is associative

OP is associative iff:

a OP (b OP c) = (a OP b) OP c = a OP b OP c

This information can be used for optimization and visualization.

Note
  • Terminals haven't arguments and cannot be associative.
  • Default (safe) value is false.

Reimplemented in vita::boolean::l_and, vita::boolean::l_or, vita::integer::add, vita::integer::mul, and vita::real::add.

Definition at line 80 of file function.h.

◆ cast()

const function * vita::function::cast ( const symbol s)
inlinestatic

This is a short cut function.

Parameters
[in]ssymbol pointer
Returns
s casted to a vita::function pointer

Definition at line 101 of file function.h.

◆ display()

std::string vita::function::display ( format  = c_format) const
virtual

◆ is_valid()

bool vita::function::is_valid ( ) const
overridevirtual
Returns
true if the object passes the internal consistency check

Reimplemented from vita::symbol.

Definition at line 64 of file function.cc.


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