Vita
Classes | Public Member Functions | Static Public Attributes | List of all members
vita::src_problem Class Reference

Provides a GP-specific interface to the generic problem class. More...

#include <problem.h>

Inherits vita::problem.

Classes

struct  default_symbols_t
 

Public Member Functions

unsigned categories () const
 
unsigned classes () const
 
bool classification () const
 Just a shorthand for checking number of classes. More...
 
dataframedata (dataset_t=dataset_t::training)
 
const dataframedata (dataset_t=dataset_t::training) const
 
bool is_valid () const override
 
bool operator! () const
 
std::size_t setup_symbols (const std::filesystem::path &, typing=typing::weak)
 Sets up the symbol set. More...
 
std::size_t setup_symbols (typing=typing::weak)
 Sets up the symbol set. More...
 
void setup_terminals (typing)
 Inserts variables and states for nominal attributes into the symbol_set. More...
 
 src_problem ()
 New empty instance of src_problem. More...
 
 src_problem (const std::filesystem::path &, const default_symbols_t &, typing=typing::weak)
 Initializes the problem with the default symbol set and data coming from a file. More...
 
 src_problem (const std::filesystem::path &, const std::filesystem::path &, typing=typing::weak)
 Initializes the problem with data / symbols coming from input files. More...
 
 src_problem (const std::filesystem::path &, typing=typing::weak)
 Initializes problem dataset with examples coming from a file. More...
 
 src_problem (std::istream &, typing=typing::weak)
 Initializes problem dataset with examples coming from a file. More...
 
unsigned variables () const
 
- Public Member Functions inherited from vita::problem
template<class S , class ... Args>
symbolinsert (Args &&... args)
 Adds a symbol to the internal symbol set. More...
 
template<class S , class ... Args>
symbolinsert (Args &&...)
 
virtual bool is_valid () const
 
 problem ()
 A new problem. More...
 

Static Public Attributes

static const default_symbols_t default_symbols = {}
 

Additional Inherited Members

- Public Attributes inherited from vita::problem
environment env
 
symbol_set sset
 

Detailed Description

Provides a GP-specific interface to the generic problem class.

The class is a facade that provides a simpler interface to represent symbolic regression / classification tasks.

Examples
titanic01.cc.

Definition at line 43 of file gp/src/problem.h.

Constructor & Destructor Documentation

◆ src_problem() [1/5]

vita::src_problem::src_problem ( )

New empty instance of src_problem.

Warning
Users must initialize:
  • the training dataset;
  • the entire symbol set (functions and terminals) before starting the evolution.

Definition at line 79 of file gp/src/problem.cc.

◆ src_problem() [2/5]

vita::src_problem::src_problem ( const std::filesystem::path &  ds,
typing  t = typing::weak 
)
explicit

Initializes problem dataset with examples coming from a file.

Parameters
[in]dsname of the dataset file (CSV or XRFF format)
[in]tweak or strong typing
Warning
  • Users must specify, at least, the functions to be used;
  • terminals directly derived from the data (variables / labels) are automatically inserted;
  • any additional terminal (ephemeral random constant, problem specific constant...) can be manually inserted.

Definition at line 96 of file gp/src/problem.cc.

◆ src_problem() [3/5]

vita::src_problem::src_problem ( std::istream &  ds,
typing  t = typing::weak 
)
explicit

Initializes problem dataset with examples coming from a file.

Parameters
[in]dsdataset
[in]tweak or strong typing
Warning
  • Users must specify, at least, the functions to be used;
  • terminals directly derived from the data (variables / labels) are automatically inserted;
  • any additional terminal (ephemeral random constant, problem specific constants...) can be manually inserted.

Definition at line 123 of file gp/src/problem.cc.

◆ src_problem() [4/5]

vita::src_problem::src_problem ( const std::filesystem::path &  ds,
const default_symbols_t ,
typing  t = typing::weak 
)

Initializes the problem with the default symbol set and data coming from a file.

Parameters
[in]dsname of the dataset file
[in]tweak or strong typing

Mainly useful for simple problems (single category regression / classification) or for the initial approach.

Definition at line 146 of file gp/src/problem.cc.

◆ src_problem() [5/5]

vita::src_problem::src_problem ( const std::filesystem::path &  ds,
const std::filesystem::path &  symbols,
typing  t = typing::weak 
)

Initializes the problem with data / symbols coming from input files.

Parameters
[in]dsname of the training dataset file
[in]symbolsname of the file containing the symbols to be used.
[in]tweak or strong typing

Definition at line 159 of file gp/src/problem.cc.

Member Function Documentation

◆ categories()

unsigned vita::src_problem::categories ( ) const
Returns
number of categories of the problem (>= 1)

Definition at line 470 of file gp/src/problem.cc.

◆ classes()

unsigned vita::src_problem::classes ( ) const
Returns
number of classes of the problem (== 0 for a symbolic regression problem, > 1 for a classification problem)

Definition at line 479 of file gp/src/problem.cc.

◆ classification()

bool vita::src_problem::classification ( ) const
inline

Just a shorthand for checking number of classes.

Definition at line 70 of file gp/src/problem.h.

◆ data() [1/2]

dataframe & vita::src_problem::data ( dataset_t  t = dataset_t::training)
Parameters
[in]ta dataset type
Returns
a reference to the specified dataset

Definition at line 497 of file gp/src/problem.cc.

◆ data() [2/2]

const dataframe & vita::src_problem::data ( dataset_t  t = dataset_t::training) const
Parameters
[in]ta dataset type
Returns
a const reference to the specified dataset

Definition at line 506 of file gp/src/problem.cc.

◆ is_valid()

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

Reimplemented from vita::problem.

Definition at line 514 of file gp/src/problem.cc.

◆ operator!()

bool vita::src_problem::operator! ( ) const
Returns
false if the current problem isn't ready for a run

Definition at line 177 of file gp/src/problem.cc.

◆ setup_symbols() [1/2]

std::size_t vita::src_problem::setup_symbols ( const std::filesystem::path &  file,
typing  t = typing::weak 
)

Sets up the symbol set.

Parameters
[in]filename of the file containing the symbols
Returns
number of parsed symbols

If a file isn't specified, a predefined set is arranged (useful for simple problems: single category regression / classification).

Warning
Data should be loaded before symbols: without data we don't know, among other things, the features the dataset has.

Definition at line 274 of file gp/src/problem.cc.

◆ setup_symbols() [2/2]

std::size_t vita::src_problem::setup_symbols ( typing  t = typing::weak)

Sets up the symbol set.

Parameters
[in]tweak or strong typing
Returns
number of parsed symbols

A predefined set is arranged (useful for simple problems: single category regression / classification).

Warning
Data should be loaded before symbols: without data we don't know, among other things, the features the dataset has.

Definition at line 256 of file gp/src/problem.cc.

◆ setup_terminals()

void vita::src_problem::setup_terminals ( typing  t)

Inserts variables and states for nominal attributes into the symbol_set.

Parameters
[in]tweak or strong typing
Exceptions
`std::data_format`unsupported state domain

There is one variable for each feature.

The names used for variables, if not specified in the dataset, are in the form X1, ... Xn.

Definition at line 194 of file gp/src/problem.cc.

◆ variables()

unsigned vita::src_problem::variables ( ) const
Returns
dimension of the input vectors (i.e. the number of variable of the problem)

Definition at line 488 of file gp/src/problem.cc.

Member Data Documentation

◆ default_symbols

const src_problem::default_symbols_t vita::src_problem::default_symbols = {}
static

Definition at line 53 of file gp/src/problem.h.


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