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:

## 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< SelectionMetrics > | createSelectionMetrics ()
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::TPGGraph > | getGraph ()
| 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 SelectionContext & | updateContext ()
| 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::TPGGraph > | graph
| TPGGraph on which the TPGVertex can be selected or deleted.
const Learn::LearningParameters & | params
| 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] | graph | shared pointer of the graph on which the selection is done.
  [in] | params | parameters 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] | results | a multimap containing root TPGVertex associated to their score during an evaluation.
  [in] | rng | Random 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] | results | a multimap containing root TPGVertex associated to their score during an evaluation.
  [in] | rng | Random Number Generator used in the mutation process.

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] | results | Map 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] | results | Map 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] | results | Map 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:

- D:/a/gegelati/gegelati/gegelatilib/include/selector/selector.h
- D:/a/gegelati/gegelati/gegelatilib/src/selector/selector.cpp