Vita
Classes | Public Types | Public Member Functions | Friends | Related Functions | List of all members
vita::i_mep Class Reference

A MEP (Multi Expression Programming) single member of a population. More...

#include <i_mep.h>

Inherits vita::individual< i_mep >.

Classes

class  basic_iterator
 

Public Types

using const_iterator = basic_iterator< true >
 
enum  crossover_t {
  one_point , two_points , tree , uniform ,
  NUM_CROSSOVERS
}
 
using iterator = basic_iterator< false >
 
using value_type = gene
 

Public Member Functions

unsigned active_symbols () const
 Number of active symbols. More...
 
iterator begin ()
 
const_iterator begin () const
 
locus best () const
 
std::set< locusblocks () const
 Calculates a set of loci referring to blocks contained in the individual. More...
 
category_t categories () const
 
category_t category () const
 
i_mep cse () const
 A sort of "common subexpression elimination" optimization. More...
 
i_mep destroy_block (index_t, const symbol_set &) const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
i_mep get_block (const locus &) const
 
 i_mep (const problem &)
 Generates the initial, random expressions that make up an individual. More...
 
 i_mep (const std::vector< gene > &)
 Creates a new individual containing genes from gv. More...
 
bool is_valid () const
 
unsigned mutation (double, const problem &)
 A new individual is created mutating this. More...
 
bool operator== (const i_mep &) const
 
const geneoperator[] (locus) const
 
i_mep replace (const gene &) const
 Creates a new individual obtained from this replacing the original symbol at locus best() with g. More...
 
i_mep replace (const locus &, const gene &) const
 Create a new individual obtained from this replacing the original symbol at locus l with g. More...
 
hash_t signature () const
 Signature maps syntactically distinct (but logically equivalent) individuals to the same value. More...
 
unsigned size () const
 
- Public Member Functions inherited from vita::individual< i_mep >
unsigned age () const
 
void inc_age ()
 
bool load (std::istream &, const symbol_set &=symbol_set())
 
bool save (std::ostream &) const
 

Friends

template<bool >
class basic_iterator
 
i_mep crossover (const i_mep &, const i_mep &)
 
class individual< i_mep >
 

Related Functions

(Note that these are not member functions.)

i_mep crossover (const i_mep &lhs, const i_mep &rhs)
 A Self-Adaptive Crossover operator. More...
 
unsigned distance (const i_mep &lhs, const i_mep &rhs)
 
std::ostream & operator<< (std::ostream &s, const i_mep &ind)
 

Additional Inherited Members

- Protected Member Functions inherited from vita::individual< i_mep >
void set_older_age (unsigned)
 
- Protected Attributes inherited from vita::individual< i_mep >
hash_t signature_
 

Detailed Description

A MEP (Multi Expression Programming) single member of a population.

Each individual contains a genome which represents a possible solution to the task being tackled (i.e. a point in the search space).

Examples
example6.cc.

Definition at line 33 of file i_mep.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 76 of file i_mep.h.

◆ iterator

Definition at line 77 of file i_mep.h.

◆ value_type

Definition at line 78 of file i_mep.h.

Member Enumeration Documentation

◆ crossover_t

enum vita::i_mep::crossover_t

Definition at line 43 of file i_mep.h.

Constructor & Destructor Documentation

◆ i_mep() [1/3]

vita::i_mep::i_mep ( )
inline

Definition at line 36 of file i_mep.h.

◆ i_mep() [2/3]

vita::i_mep::i_mep ( const problem p)
explicit

Generates the initial, random expressions that make up an individual.

Parameters
[in]pbase problem

The constructor is implemented so as to ensure that there is no violation of the type system's constraints.

Definition at line 33 of file i_mep.cc.

◆ i_mep() [3/3]

vita::i_mep::i_mep ( const std::vector< gene > &  gv)
explicit

Creates a new individual containing genes from gv.

Parameters
[in]gvvector of genes

This is useful for debugging purpose (i.e. setup ad-hoc individuals).

Definition at line 65 of file i_mep.cc.

Member Function Documentation

◆ active_symbols()

unsigned vita::i_mep::active_symbols ( ) const

Number of active symbols.

Returns
number of active symbols
See also
size()

When category() > 1, active_symbols() can be greater than size(). For instance consider the following individual:

[0, 1] FIFL 1 2 2 3
[1, 0] "car"
[2, 0] "plane"
[2, 1] 10
[3, 1] 20

size() == 4 (four slots / rows) and active_symbols() == 5.

Definition at line 103 of file i_mep.cc.

◆ begin() [1/2]

i_mep::iterator vita::i_mep::begin ( )
inline
Returns
an iterator to the first active locus of the individual

Definition at line 187 of file i_mep.h.

◆ begin() [2/2]

i_mep::const_iterator vita::i_mep::begin ( ) const
inline
Returns
an iterator to the first active locus of the individual

Definition at line 171 of file i_mep.h.

◆ best()

locus vita::i_mep::best ( ) const
inline
Returns
the starting locus of the best sequence available

Definition at line 119 of file i_mep.h.

◆ blocks()

std::set< locus > vita::i_mep::blocks ( ) const

Calculates a set of loci referring to blocks contained in the individual.

Returns
a set of loci

A locus obtained with this function is usually an argument for the i_mep::get_block function.

Note
A block is a subset of the active code composed of, at least, a function.

Definition at line 179 of file i_mep.cc.

◆ categories()

category_t vita::i_mep::categories ( ) const
inline
Returns
the total number of categories the individual is using

Definition at line 136 of file i_mep.h.

◆ category()

category_t vita::i_mep::category ( ) const
Returns
the category of the individual

Definition at line 245 of file i_mep.cc.

◆ cse()

i_mep vita::i_mep::cse ( ) const

A sort of "common subexpression elimination" optimization.

Returns
a CSE-optimized individual

The function doesn't rely on the meaning of the symbols, just on the genome layout.

Some features of the cse-optimized individual are:

  • same signature of the unoptimized one;
  • the interpretation yields the same value of the unoptimized one;
  • the unoptimized individual has more active symbols.

Definition at line 605 of file i_mep.cc.

◆ destroy_block()

i_mep vita::i_mep::destroy_block ( index_t  index,
const symbol_set sset 
) const
Parameters
[in]sseta symbol set
[in]indexindex of a symbol in the individual
Returns
a new individual obtained from this inserting a random terminal at index index

Definition at line 227 of file i_mep.cc.

◆ empty()

bool vita::i_mep::empty ( ) const
inline
Returns
true if the individual isn't initialized

Definition at line 157 of file i_mep.h.

◆ end() [1/2]

i_mep::iterator vita::i_mep::end ( )
inline
Returns
an iterator used as sentry value to stop a cycle

Definition at line 195 of file i_mep.h.

◆ end() [2/2]

i_mep::const_iterator vita::i_mep::end ( ) const
inline
Returns
an iterator used as sentry value to stop a cycle

Definition at line 179 of file i_mep.h.

◆ get_block()

i_mep vita::i_mep::get_block ( const locus l) const
Parameters
[in]llocus of the genome
Returns
an individual obtained from this choosing the gene sequence starting at l
Note
This function is often used along with the i_mep::blocks function.

Definition at line 115 of file i_mep.cc.

◆ is_valid()

bool vita::i_mep::is_valid ( ) const
Returns
true if the individual passes the internal consistency check

Definition at line 398 of file i_mep.cc.

◆ mutation()

unsigned vita::i_mep::mutation ( double  pgm,
const problem prb 
)

A new individual is created mutating this.

Parameters
[in]pgmprobability of gene mutation
[in]prbthe current problem
Returns
number of mutations performed

Definition at line 136 of file i_mep.cc.

◆ operator==()

bool vita::i_mep::operator== ( const i_mep x) const
Parameters
[in]xsecond term of comparison.
Returns
true if the two individuals are equal (symbol by symbol, including introns)
Note
Age is not checked.

Definition at line 257 of file i_mep.cc.

◆ operator[]()

const gene & vita::i_mep::operator[] ( locus  l) const
inline
Parameters
[in]llocus of a gene
Returns
the l-th gene of this individual

Definition at line 128 of file i_mep.h.

◆ replace() [1/2]

i_mep vita::i_mep::replace ( const gene g) const

Creates a new individual obtained from this replacing the original symbol at locus best() with g.

Parameters
[in]gnew gene for replacement
Returns
a new individual with gene at locus best() replaced by g

Definition at line 216 of file i_mep.cc.

◆ replace() [2/2]

i_mep vita::i_mep::replace ( const locus l,
const gene g 
) const

Create a new individual obtained from this replacing the original symbol at locus l with g.

Parameters
[in]llocus where replacement takes place
[in]gnew gene for replacement
Returns
a new individual with gene at locus l replaced by g

Definition at line 198 of file i_mep.cc.

◆ signature()

hash_t vita::i_mep::signature ( ) const

Signature maps syntactically distinct (but logically equivalent) individuals to the same value.

Returns
the signature of this individual.

In other words identical individuals at genotypic level have the same signature; different individuals at the genotipic level may be mapped to the same signature since the value of terminals is considered and not the index.

This is a very interesting property, useful for individual comparison, information retrieval, entropy calculation...

Definition at line 387 of file i_mep.cc.

◆ size()

unsigned vita::i_mep::size ( ) const
inline
Returns
the total size of the individual (effective size + introns)
Remarks
Size is constant for any individual (it's chosen at initialization time).
See also
eff_size()

Definition at line 149 of file i_mep.h.

Friends And Related Function Documentation

◆ basic_iterator

template<bool >
friend class basic_iterator
friend

Definition at line 86 of file i_mep.h.

◆ crossover()

i_mep crossover ( const i_mep lhs,
const i_mep rhs 
)
related

A Self-Adaptive Crossover operator.

Parameters
[in]lhsfirst parent
[in]rhssecond parent
Returns
the result of the crossover (we only generate a single offspring).

Well known elementary crossover operators traverse the problem domain in different ways, exhibiting variable performances and specific problems. An attempt to make the algorithm more robust is combining various search strategies, encapsulated by the different elementary crossover operators available, via self adaptation.

We associate to each individual the type of crossover used to create it (initially this is set to a random type). This type is used afterwards to determine which crossover to apply and allows the algorithm to adjust the relative mixture of operators.

Here we briefly describe the elementary crossover operators that are utilised:

ONE POINT

We randomly select a parent (between from and to) and a single locus (common crossover point). The offspring is created with genes from the chosen parent up to the crossover point and genes from the other parent beyond that point. One-point crossover is the oldest homologous crossover in tree-based GP.

TREE

Inserts a complete tree from one parent into the other. The operation is less disruptive than other forms of crossover since an entire tree is copied (not just a part).

TWO POINTS

We randomly select two loci (common crossover points). The offspring is created with genes from the one parent before the first crossover point and after the second crossover point; genes between crossover points are taken from the other parent.

UNIFORM CROSSOVER

The i-th locus of the offspring has a 50% probability to be filled with the i-th gene of from and 50% with i-th gene of to.

Uniform crossover, as the name suggests, is a GP operator inspired by the GA operator of the same name (G. Syswerda. Uniform crossover in genetic algorithms - Proceedings of the Third International Conference on Genetic Algorithms. 1989). GA uniform crossover constructs offspring on a bitwise basis, copying each allele from each parent with a 50% probability. Thus the information at each gene location is equally likely to have come from either parent and on average each parent donates 50% of its genetic material. The whole operation, of course, relies on the fact that all the chromosomes in the population are of the same structure and the same length. GP uniform crossover begins with the observation that many parse trees are at least partially structurally similar.

Note
Parents must have the same size.
Remarks
What has to be noticed is that the adaption of the parameter happens before the fitness is given to it. That means that getting a good parameter doesn't rise the individual's fitness but only its performance over time.
See also
https://github.com/morinim/vita/wiki/bibliography#6

Definition at line 734 of file i_mep.cc.

◆ distance()

unsigned distance ( const i_mep lhs,
const i_mep rhs 
)
related
Parameters
[in]lhsfirst term of comparison
[in]rhssecond term of comparison
Returns
a numeric measurement of the difference between lhs and rhs (the number of different genes between individuals)
Examples
pathfinding01.cc, and pathfinding02.cc.

Definition at line 286 of file i_mep.cc.

◆ individual< i_mep >

friend class individual< i_mep >
friend

Definition at line 86 of file i_mep.h.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  s,
const i_mep ind 
)
related
Parameters
[out]soutput stream
[in]indindividual to print
Returns
output stream including ind

Definition at line 1003 of file i_mep.cc.


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