GEGELATI

Loading...
Searching...
No Matches
learningAgent.h
1
39#ifndef LEARNING_AGENT_H
40#define LEARNING_AGENT_H
41
42#include <map>
43#include <queue>
44
45#include "archive.h"
46#include "environment.h"
47#include "instructions/set.h"
48#include "log/laLogger.h"
49#include "mutator/mutationParameters.h"
50#include "tpg/tpgExecutionEngine.h"
51#include "tpg/tpgGraph.h"
52
53#include "learn/classificationLearningEnvironment.h"
54#include "learn/evaluationResult.h"
55#include "learn/job.h"
56#include "learn/learningEnvironment.h"
57#include "learn/learningParameters.h"
58
59#include "selector/selectorFactory.h"
60 namespace Learn {
61
66 class LearningAgent
67 {
68 protected:
70 LearningEnvironment& learningEnvironment;
71
73 Environment env;
74
76 Archive archive;
77
79 LearningParameters params;
80
82 std::shared_ptr<TPG::TPGGraph> tpg;
83
85 std::shared_ptr<Selector::Selector> selector;
86
88 Mutator::RNG rng;
89
91 uint64_t maxNbThreads = 1;
92
100 std::vector<std::reference_wrapper<Log::LALogger>> loggers;
101
102 public:
113 LearningAgent(LearningEnvironment& le, const Instructions::Set& iSet,
114 const LearningParameters& p,
115 const TPG::TPGFactory& factory = TPG::TPGFactory())
116 : learningEnvironment{le},
117 env(iSet, p, le.getDataSources(),
118 (le.isDiscrete()) ? 0 : le.getNbActions()),
119 archive(p.archiveSize, p.archivingProbability), params{p},
120 tpg(factory.createTPGGraph(env)),
121 selector{Selector::selectorFactory(tpg, le, p)} {};
122
124 virtual ~LearningAgent() = default;
125
131 std::shared_ptr<TPG::TPGGraph> getTPGGraph();
132
138 std::shared_ptr<Selector::Selector> getSelector();
139
145 const Archive& getArchive() const;
146
152 const Environment& getEnvironment() const;
153
159 Mutator::RNG& getRNG();
160
171 void addLogger(Log::LALogger& logger);
172
201 virtual std::shared_ptr<EvaluationResult> evaluateJob(
202 TPG::TPGExecutionEngine& tee, const Job& job,
203 uint64_t generationNumber, LearningMode mode,
204 LearningEnvironment& le) const;
205
221 bool isRootEvalSkipped(
222 const TPG::TPGVertex& root,
223 std::shared_ptr<Learn::EvaluationResult>& previousResult) const;
224
237 virtual std::multimap<std::shared_ptr<EvaluationResult>,
238 const TPG::TPGVertex*>
239 evaluateAllRoots(uint64_t generationNumber, LearningMode mode);
240
258 virtual std::shared_ptr<EvaluationResult> evaluateOneRoot(
259 uint64_t generationNumber, LearningMode mode,
260 const TPG::TPGVertex* root);
261
277 virtual void trainOneGeneration(uint64_t generationNumber,
278 bool doPopulate = true);
279
294 virtual uint64_t train(volatile bool& altTraining,
295 bool printProgressBar);
296
310 virtual std::shared_ptr<Learn::Job> makeJob(
311 const TPG::TPGVertex* vertex, Learn::LearningMode mode, int idx = 0,
312 TPG::TPGGraph* tpgGraph = nullptr);
313
325 virtual std::queue<std::shared_ptr<Learn::Job>> makeJobs(
326 Learn::LearningMode mode, TPG::TPGGraph* tpgGraph = nullptr);
327
337 virtual void init(uint64_t seed = 0);
338 };
339}; // namespace Learn
340
341#endif
Archive
Definition archive.h:80
Environment
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
Instructions::Set
Class for storing a set of Instruction.
Definition set.h:55
Learn::Job
This class embeds roots for the simulations.
Definition job.h:53
Learn::LearningAgent
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment.
Definition learningAgent.h:67
Learn::LearningAgent::addLogger
void addLogger(Log::LALogger &logger)
Adds a LALogger to the loggers vector.
Definition learningAgent.cpp:98
Learn::LearningAgent::getTPGGraph
std::shared_ptr< TPG::TPGGraph > getTPGGraph()
Getter for the TPGGraph built by the LearningAgent.
Definition learningAgent.cpp:51
Learn::LearningAgent::maxNbThreads
uint64_t maxNbThreads
Control the maximum number of threads when running in parallel.
Definition learningAgent.h:91
Learn::LearningAgent::getArchive
const Archive & getArchive() const
Getter for the Archive filled by the LearningAgent.
Definition learningAgent.cpp:61
Learn::LearningAgent::selector
std::shared_ptr< Selector::Selector > selector
Selector used for the selection process.
Definition learningAgent.h:85
Learn::LearningAgent::evaluateAllRoots
virtual std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > evaluateAllRoots(uint64_t generationNumber, LearningMode mode)
Evaluate all root TPGVertex of the TPGGraph.
Definition learningAgent.cpp:206
Learn::LearningAgent::params
LearningParameters params
Parameters for the learning process.
Definition learningAgent.h:79
Learn::LearningAgent::LearningAgent
LearningAgent(LearningEnvironment &le, const Instructions::Set &iSet, const LearningParameters &p, const TPG::TPGFactory &factory=TPG::TPGFactory())
Constructor for LearningAgent.
Definition learningAgent.h:113
Learn::LearningAgent::archive
Archive archive
Archive used during the training process.
Definition learningAgent.h:76
Learn::LearningAgent::init
virtual void init(uint64_t seed=0)
Initialize the LearningAgent.
Definition learningAgent.cpp:76
Learn::LearningAgent::makeJobs
virtual std::queue< std::shared_ptr< Learn::Job > > makeJobs(Learn::LearningMode mode, TPG::TPGGraph *tpgGraph=nullptr)
Puts all roots into jobs to be able to use them in simulation later.
Definition learningAgent.cpp:382
Learn::LearningAgent::evaluateOneRoot
virtual std::shared_ptr< EvaluationResult > evaluateOneRoot(uint64_t generationNumber, LearningMode mode, const TPG::TPGVertex *root)
Evaluate one root TPGVertex of the TPGGraph.
Definition learningAgent.cpp:231
Learn::LearningAgent::rng
Mutator::RNG rng
Random Number Generator for this Learning Agent.
Definition learningAgent.h:88
Learn::LearningAgent::learningEnvironment
LearningEnvironment & learningEnvironment
LearningEnvironment with which the LearningAgent will interact.
Definition learningAgent.h:70
Learn::LearningAgent::train
virtual uint64_t train(volatile bool &altTraining, bool printProgressBar)
Train the TPGGraph for a given number of generation.
Definition learningAgent.cpp:316
Learn::LearningAgent::loggers
std::vector< std::reference_wrapper< Log::LALogger > > loggers
Set of LALogger called throughout the training process.
Definition learningAgent.h:100
Learn::LearningAgent::trainOneGeneration
virtual void trainOneGeneration(uint64_t generationNumber, bool doPopulate=true)
Train the TPGGraph for one generation.
Definition learningAgent.cpp:261
Learn::LearningAgent::isRootEvalSkipped
bool isRootEvalSkipped(const TPG::TPGVertex &root, std::shared_ptr< Learn::EvaluationResult > &previousResult) const
Method detecting whether a root should be evaluated again.
Definition learningAgent.cpp:106
Learn::LearningAgent::~LearningAgent
virtual ~LearningAgent()=default
Default destructor for polymorphism.
Learn::LearningAgent::getRNG
Mutator::RNG & getRNG()
Getter for the RNG used by the LearningAgent.
Definition learningAgent.cpp:71
Learn::LearningAgent::tpg
std::shared_ptr< TPG::TPGGraph > tpg
TPGGraph built during the learning process.
Definition learningAgent.h:82
Learn::LearningAgent::getSelector
std::shared_ptr< Selector::Selector > getSelector()
Getter for the Selector built by the LearningAgent.
Definition learningAgent.cpp:56
Learn::LearningAgent::env
Environment env
Environment for executing Program of the LearningAgent.
Definition learningAgent.h:73
Learn::LearningAgent::evaluateJob
virtual std::shared_ptr< EvaluationResult > evaluateJob(TPG::TPGExecutionEngine &tee, const Job &job, uint64_t generationNumber, LearningMode mode, LearningEnvironment &le) const
Evaluates policy starting from the given root.
Definition learningAgent.cpp:125
Learn::LearningAgent::makeJob
virtual std::shared_ptr< Learn::Job > makeJob(const TPG::TPGVertex *vertex, Learn::LearningMode mode, int idx=0, TPG::TPGGraph *tpgGraph=nullptr)
Takes a given TPGVertex and creates a job containing it.
Definition learningAgent.cpp:361
Learn::LearningAgent::getEnvironment
const Environment & getEnvironment() const
Accessor to the Environment of the TPGGraph.
Definition learningAgent.cpp:66
Learn::LearningEnvironment
Interface for creating a Learning Environment.
Definition learningEnvironment.h:81
Log::LALogger
Learning Agent logger class that will be called during LearningAgent executions.
Definition laLogger.h:65
Mutator::RNG
Definition rng.h:52
TPG::TPGExecutionEngine
Definition tpgExecutionEngine.h:57
TPG::TPGFactory
Factory for creating all elements constituting a TPG.
Definition tpgFactory.h:71
TPG::TPGGraph
Class for storing a Tangled-Program-Graph.
Definition tpgGraph.h:58
TPG::TPGVertex
Abstract class representing the vertices of a TPGGraph.
Definition tpgVertex.h:55
Learn
Definition classificationLearningEnvironment.h:44
Learn::LearningMode
LearningMode
Different modes in which the LearningEnvironment can be reset.
Definition learningEnvironment.h:59
Selector
Definition mapElitesArchiveLogger.h:45
Learn::LearningParameters
Structure for simplifying the transmission of LearningParameters to functions.
Definition learningParameters.h:55