Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::gp::team< I > Class Template Reference

#include <team.h>

Public Types

using members_t = std::vector<I>
using const_iterator = typename members_t::const_iterator
using value_type = typename members_t::value_type

Public Member Functions

 team (std::size_t)
 team (const problem &)
 team (std::vector< I >)
unsigned mutation (const problem &, double=1.0)
void apply_decision_vector (const team_decision_vector &v)
const I & operator[] (std::size_t) const
bool empty () const noexcept
std::size_t size () const noexcept
hash_t signature () const noexcept
ultra::individual::age_t age () const
void inc_age (unsigned=1)
bool is_valid () const
const_iterator begin () const noexcept
const_iterator end () const noexcept
bool load (std::istream &, const symbol_set &)
bool save (std::ostream &) const

Static Public Attributes

static constexpr std::size_t max_team_size {1024}
 Maximum allowed number of individuals in a team.

Friends

template<Individual U>
team< U > crossover (const problem &, const team< U > &, const team< U > &)

(Note that these are not member symbols.)

template<Individual I>
team< I > crossover (const problem &prb, const team< I > &lhs, const team< I > &rhs)
template<Individual I>
team_decision_vector extract_decision_vector (const team< I > &t)
template<Individual I>
unsigned active_slots (const team< I > &t)
template<Individual I>
bool operator== (const team< I > &lhs, const team< I > &rhs) noexcept
template<Individual I>
unsigned distance (const team< I > &lhs, const team< I > &rhs)
template<Individual I>
std::ostream & operator<< (std::ostream &s, const team< I > &t)

Detailed Description

template<Individual I>
class ultra::gp::team< I >

A collection of cooperating individuals used as a member of ultra::population.

In general, teams of individuals can be implemented in different ways.

  • Firstly, a certain number of individuals can be selected randomly from the population and evaluated in combination as a team (but we have a credit assignment problem).
  • Secondly, team members can be evolved in separate subpopulations which provide a more specialized development.
  • We can use an explicit team representation that is considered as one individual by the evolutionary algorithm. The population is subdivided into fixed, equal-sized groups of individuals. Each program is assigned a fixed position index in its team (program vector). The members of a team undergo a coevolutionary process because they are always selected, evaluated and varied simultaneously. This eliminates the credit assignment problem and renders the composition of teams an object of evolution.
Note
The team size has to be large enough to cause an improved prediction compared to the traditional approach, i.e. team size one (but the complexity of the search space and the training time, respectively, grow exponentially with the number of coevolved programs).
See also
https://github.com/morinim/ultra/wiki/bibliography#16

Constructor & Destructor Documentation

◆ team() [1/3]

template<Individual I>
team::team ( std::size_t n)
explicit

Allocates space for a given number of individuals.

◆ team() [2/3]

template<Individual I>
team::team ( const problem & p)
explicit

Creates a team of individuals that will cooperate to solve a task.

◆ team() [3/3]

template<Individual I>
team::team ( std::vector< I > v)
explicit

Builds a team containing the individuals of a given vector.

Parameters
[in]va vector of individuals

Member Function Documentation

◆ age()

template<Individual I>
ultra::individual::age_t team::age ( ) const
nodiscard
Returns
the age of the team (average age of the team members)

◆ apply_decision_vector()

template<Individual I>
void team::apply_decision_vector ( const team_decision_vector & v)

Applies a flat team decision vector to the corresponding team members.

Parameters
[in]vdecision vector to be written back
Precondition
  • v.is_valid();
  • v must have been obtained from a team with the same structure (same number of individuals, active exons, loci, and argument layout). Applying a decision vector to a structurally different team results in undefined behaviour.
Postcondition
is_valid()

The entries of v are first regrouped by team member, then each member receives its own individual-level decision vector via I::apply_decision_vector().

This function updates only numeric arguments; it does not alter the team structure nor the structure of the contained individuals.

◆ begin()

template<Individual I>
team< I >::const_iterator team::begin ( ) const
nodiscardnoexcept
Returns
an iterator pointing to the first individual of the team

◆ empty()

template<Individual I>
bool team::empty ( ) const
nodiscardnoexcept
Returns
true if the team is empty, false otherwise

◆ end()

template<Individual I>
team< I >::const_iterator team::end ( ) const
nodiscardnoexcept
Returns
an iterator pointing to an end-of-team sentry

◆ inc_age()

template<Individual I>
void team::inc_age ( unsigned delta = 1)

Increments the age of every element of the team.

Parameters
[in]deltavariation of age

◆ is_valid()

template<Individual I>
bool team::is_valid ( ) const
nodiscard
Returns
true if the team passes the internal consistency check

◆ load()

template<Individual I>
bool team::load ( std::istream & in,
const symbol_set & ss )
Parameters
[in]ininput stream
[in]ssactive symbol set
Returns
true if team was loaded correctly
Note
If the load operation isn't successful the current team isn't modified.

◆ mutation()

template<Individual I>
unsigned team::mutation ( const problem & prb,
double temperature = 1.0 )

Mutates the individuals in this team and returns the number of mutations performed.

Parameters
[in]prbcurrent problem
[in]temperaturemutation intensity (1.0 preserves the configured probability)
Returns
number of mutations performed
Note
External parameters: evolution.p_mutation

◆ operator[]()

template<Individual I>
const I & team::operator[] ( std::size_t i) const
nodiscard
Parameters
[in]iindex of a member of the team
Returns
the i-th member of the team

◆ save()

template<Individual I>
bool team::save ( std::ostream & out) const
Parameters
[out]outoutput stream
Returns
true if team was saved correctly

◆ signature()

template<Individual I>
hash_t team::signature ( ) const
nodiscardnoexcept

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

Returns
the signature of this team

In other words identical teams, at genotypic level, have the same signature; different teams at the genotypic 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 comparison, information retrieval, entropy calculation...

◆ size()

template<Individual I>
std::size_t team::size ( ) const
nodiscardnoexcept
Returns
number of individuals of the team

◆ active_slots()

template<Individual I>
unsigned active_slots ( const team< I > & t)
related

Total number of active functions.

\paramp[in] t team to be analyzed

Returns
number of active functions in the team
See also
team::size()

◆ crossover()

template<Individual I>
team< I > crossover ( const problem & prb,
const team< I > & lhs,
const team< I > & rhs )
related
Parameters
[in]prbcurrent problem
[in]lhsfirst parent
[in]rhssecond parent
Returns
the result of the crossover (we only generate a single offspring)
See also
individual::crossover for further details.

◆ distance()

template<Individual I>
unsigned distance ( const team< I > & lhs,
const team< I > & rhs )
related
Parameters
[in]lhsfirst term of comparison
[in]rhssecond term of comparison
Returns
a numeric measurement of the difference between x and this (the number of different genes between teams)

◆ extract_decision_vector()

template<Individual I>
team_decision_vector extract_decision_vector ( const team< I > & t)
related

Extracts a flat decision vector from a team.

Parameters
[in]tteam to analyse
Returns
a valid team decision vector

The resulting vector is obtained by concatenating the decision vectors of all member individuals. Each extracted coordinate is extended with the index of the corresponding team member so that the parameter can later be written back to the correct individual.

◆ operator<<()

template<Individual I>
std::ostream & operator<< ( std::ostream & s,
const team< I > & t )
related
Parameters
[out]soutput stream
[in]tteam to print
Returns
output stream including t

◆ operator==()

template<Individual I>
bool operator== ( const team< I > & lhs,
const team< I > & rhs )
related
Parameters
[in]lhsfirst term of comparison
[in]rhssecond term of comparison
Returns
true if the two teams are equal (individual by individual)
Note
Age is not checked.

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