GEGELATI
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Selector::Selector Class Reference

Abstract class for the selection classes, that will choose which agents survived or not at each generation. More...

#include <selector.h>

Inheritance diagram for Selector::Selector:
Selector::ClassificationSelector Selector::MapElites::MapElitesSelector Selector::TournamentSelector Selector::TruncationSelector

Public Member Functions

 Selector (std::shared_ptr< TPG::TPGGraph > graph, const Learn::LearningParameters &params)
 Constructor for Selector.
 
virtual void launchSelection (std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > &results, Mutator::RNG &rng)
 This method execute the doSelection method.
 
virtual void doSelection (std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > &results, Mutator::RNG &rng)
 Removes from the TPGGraph the root TPGVertex.
 
virtual std::shared_ptr< SelectionMetricscreateSelectionMetrics ()
 
virtual void keepBestPolicy ()
 This method keeps only the bes tRoot policy in the TPGGraph.
 
virtual void updateEvaluationRecords (const std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > &results)
 Update the bestRoot and resultsPerRoot attributes.
 
virtual void updateResultsPerRoot (const std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > &results)
 Update the resultsPerRoot.
 
virtual void updateBestRoot (const std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > &results)
 Update the bestRoot attribute.
 
virtual const std::pair< const TPG::TPGVertex *, std::shared_ptr< Learn::EvaluationResult > > & getBestRoot () const
 Get the best root TPG::Vertex encountered since the last init.
 
virtual std::shared_ptr< TPG::TPGGraphgetGraph ()
 Getter for the TPGGraph built by the LearningAgent.
 
virtual void forgetPreviousResults ()
 This method resets the previous registered scores per root.
 
virtual const std::map< const TPG::TPGVertex *, std::shared_ptr< Learn::EvaluationResult > > & getResultsPerRoot () const
 Return the resultsPerRoot map.
 
virtual const SelectionContextupdateContext ()
 Update the SelectionContext structure and return it.
 
virtual void updateAfterPopulate ()
 Method to call at the end of TPGMutator::populateTPG.
 

Protected Attributes

std::shared_ptr< TPG::TPGGraphgraph
 TPGGraph on which the TPGVertex can be selected or deleted.
 
const Learn::LearningParametersparams
 Parameters for the selection.
 
std::pair< const TPG::TPGVertex *, std::shared_ptr< Learn::EvaluationResult > > bestRoot {nullptr, nullptr}
 
std::map< const TPG::TPGVertex *, std::shared_ptr< Learn::EvaluationResult > > resultsPerRoot
 Map associating root TPG::TPGVertex to their EvaluationResult.
 
SelectionContext context
 context used by the TPGMutator to populate the TPGGraph.
 

Detailed Description

Abstract class for the selection classes, that will choose which agents survived or not at each generation.

Constructor & Destructor Documentation

◆ Selector()

Selector::Selector::Selector ( std::shared_ptr< TPG::TPGGraph > graph,
const Learn::LearningParameters & params )
inline

Constructor for Selector.

Parameters
[in]graphshared pointer of the graph on which the selection is done.
[in]paramsparameters used by the Selector.

Member Function Documentation

◆ createSelectionMetrics()

std::shared_ptr< Selector::SelectionMetrics > Selector::Selector::createSelectionMetrics ( )
virtual

Creates and return an instance of SelectionMetrics

The purpose of this method is to be override by new selection algorithms to use specific metrics.

Reimplemented in Selector::ClassificationSelector, and Selector::MapElites::MapElitesSelector.

◆ doSelection()

void Selector::Selector::doSelection ( std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & results,
Mutator::RNG & rng )
virtual

Removes from the TPGGraph the root TPGVertex.

The given multimap is updated by removing entries corresponding to decimated vertices.

The resultsPerRoot attribute is updated to remove results associated to removed vertices.

Parameters
[in,out]resultsa multimap containing root TPGVertex associated to their score during an evaluation.
[in]rngRandom Number Generator used in the mutation process.

Reimplemented in Selector::ClassificationSelector, Selector::MapElites::MapElitesSelector, Selector::TournamentSelector, and Selector::TruncationSelector.

◆ forgetPreviousResults()

void Selector::Selector::forgetPreviousResults ( )
virtual

This method resets the previous registered scores per root.

Resets resultsPerRoot so that, in the next training, the current roots will be considered as if they had never been tested. To use for example when there is a scoring policy change.

◆ getBestRoot()

const std::pair< const TPG::TPGVertex *, std::shared_ptr< Learn::EvaluationResult > > & Selector::Selector::getBestRoot ( ) const
virtual

Get the best root TPG::Vertex encountered since the last init.

The returned pointers may be nullptr if no generation was trained since the last init.

Returns
a reference to the bestRoot attribute.

◆ getGraph()

std::shared_ptr< TPG::TPGGraph > Selector::Selector::getGraph ( )
virtual

Getter for the TPGGraph built by the LearningAgent.

Returns
Get a shared_pointer to the TPGGraph.

◆ keepBestPolicy()

void Selector::Selector::keepBestPolicy ( )
virtual

This method keeps only the bes tRoot policy in the TPGGraph.

If the TPGVertex referenced in the bestRoot attribute is no longer a TPGVertex of the TPGGraph, nothing happens.

◆ launchSelection()

void Selector::Selector::launchSelection ( std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & results,
Mutator::RNG & rng )
virtual

This method execute the doSelection method.

However if a double population of team and action roots is used (for MATPG case basically), it launch the doSelection two times, once with the team results, and once with the action results

Parameters
[in,out]resultsa multimap containing root TPGVertex associated to their score during an evaluation.
[in]rngRandom Number Generator used in the mutation process.

Copyright or © or Copr. IETR/INSA - Rennes (2025) :

Quentin Vacher qvach.nosp@m.er@i.nosp@m.nsa-r.nosp@m.enne.nosp@m.s.fr (2025)

GEGELATI is an open-source reinforcement learning framework for training artificial intelligence based on Tangled Program Graphs (TPGs).

This software is governed by the CeCILL-C license under French law and abiding by the rules of distribution of free software. You can use, modify and/ or redistribute the software under the terms of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".

As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.

In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and operate it in the same conditions as regards security.

The fact that you are presently reading this means that you have had knowledge of the CeCILL-C license and that you accept its terms.

Reimplemented in Selector::TournamentSelector.

◆ updateAfterPopulate()

virtual void Selector::Selector::updateAfterPopulate ( )
inlinevirtual

Method to call at the end of TPGMutator::populateTPG.

This method does nothing with the default selector.

Reimplemented in Selector::TournamentSelector.

◆ updateBestRoot()

void Selector::Selector::updateBestRoot ( const std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & results)
virtual

Update the bestRoot attribute.

This method updates the value of the bestRoot attribute with the TPG::Vertex given as an argument in the following cases:

  • The given EvaluationResult is greater than the one of the current bestRoot.
  • The current bestRoot is a nullptr.
  • The current bestRoot has been removed from the TPG::TPGGraph managed by the LearningAgent.

It should be noted that the last case alone (i.e. without validating the first one) indicates a great variability of the evaluation process as it means that a vertex currently known as the best root from previous generations, with an EvaluationResult never beaten, was removed from the graph in a following generation, beaten by root vertex with lower scores than the current record.

Parameters
[in]resultsMap from the evaluateAllRoots method.

◆ updateContext()

const Selector::SelectionContext & Selector::Selector::updateContext ( )
virtual

Update the SelectionContext structure and return it.

The context contains data needed for the creation of the new population. This method create the vectors of clonable vertices, preExistingVertices, preExistingEdges and the number of Vertices to create.

Reimplemented in Selector::MapElites::MapElitesSelector, and Selector::TournamentSelector.

◆ updateEvaluationRecords()

void Selector::Selector::updateEvaluationRecords ( const std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & results)
virtual

Update the bestRoot and resultsPerRoot attributes.

This method updates the value of the bestRoot attribute with the TPG::Vertex given as an argument in the following cases:

  • The given EvaluationResult is greater than the one of the current bestRoot.
  • The current bestRoot is a nullptr.
  • The current bestRoot has been removed from the TPG::TPGGraph managed by the LearningAgent.

It should be noted that the last case alone (i.e. without validating the first one) indicates a great variability of the evaluation process as it means that a vertex currently known as the best root from previous generations, with an EvaluationResult never beaten, was removed from the graph in a following generation, beaten by root vertex with lower scores than the current record.

Parameters
[in]resultsMap from the evaluateAllRoots method.

◆ updateResultsPerRoot()

void Selector::Selector::updateResultsPerRoot ( const std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & results)
virtual

Update the resultsPerRoot.

Parameters
[in]resultsMap from the evaluateAllRoots method.

Member Data Documentation

◆ bestRoot

std::pair<const TPG::TPGVertex*, std::shared_ptr<Learn::EvaluationResult> > Selector::Selector::bestRoot {nullptr, nullptr}
protected

Pointer to the best root encountered during training, together with its EvaluationResult.

◆ context

SelectionContext Selector::Selector::context
protected

context used by the TPGMutator to populate the TPGGraph.

The context contains various data needed for the creation of the new population and is update in the updateContext methods.

This method can be override by the different selectors to specify the data to each case.

◆ resultsPerRoot

std::map<const TPG::TPGVertex*, std::shared_ptr<Learn::EvaluationResult> > Selector::Selector::resultsPerRoot
protected

Map associating root TPG::TPGVertex to their EvaluationResult.

If a given TPGVertex is evaluated several times, its EvaluationResult may be updated with the newer results.

Whenever a TPGVertex is removed from the TPGGraph, its EvaluationResult should also be removed from this map.

This map may be used to avoid reevaluating a root that was already evaluated more than LearningParameters::maxNbEvaluationPerPolicy times.


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