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"
60namespace Learn {
61
67 {
68 protected:
71
74
77
80
82 std::shared_ptr<TPG::TPGGraph> tpg;
83
85 std::shared_ptr<Selector::Selector> selector;
86
89
91 uint64_t maxNbThreads = 1;
92
100 std::vector<std::reference_wrapper<Log::LALogger>> loggers;
101
102 public:
114 const LearningParameters& p,
115 const TPG::TPGFactory& factory = TPG::TPGFactory())
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
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
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
Definition archive.h:80
The Environment class contains all information needed to execute a Program.
Definition environment.h:86
Class for storing a set of Instruction.
Definition set.h:55
This class embeds roots for the simulations.
Definition job.h:53
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment.
Definition learningAgent.h:67
void addLogger(Log::LALogger &logger)
Adds a LALogger to the loggers vector.
Definition learningAgent.cpp:100
std::shared_ptr< TPG::TPGGraph > getTPGGraph()
Getter for the TPGGraph built by the LearningAgent.
Definition learningAgent.cpp:53
uint64_t maxNbThreads
Control the maximum number of threads when running in parallel.
Definition learningAgent.h:91
const Archive & getArchive() const
Getter for the Archive filled by the LearningAgent.
Definition learningAgent.cpp:63
std::shared_ptr< Selector::Selector > selector
Selector used for the selection process.
Definition learningAgent.h:85
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:254
LearningParameters params
Parameters for the learning process.
Definition learningAgent.h:79
LearningAgent(LearningEnvironment &le, const Instructions::Set &iSet, const LearningParameters &p, const TPG::TPGFactory &factory=TPG::TPGFactory())
Constructor for LearningAgent.
Definition learningAgent.h:113
Archive archive
Archive used during the training process.
Definition learningAgent.h:76
virtual void init(uint64_t seed=0)
Initialize the LearningAgent.
Definition learningAgent.cpp:78
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:430
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:279
Mutator::RNG rng
Random Number Generator for this Learning Agent.
Definition learningAgent.h:88
LearningEnvironment & learningEnvironment
LearningEnvironment with which the LearningAgent will interact.
Definition learningAgent.h:70
virtual uint64_t train(volatile bool &altTraining, bool printProgressBar)
Train the TPGGraph for a given number of generation.
Definition learningAgent.cpp:364
std::vector< std::reference_wrapper< Log::LALogger > > loggers
Set of LALogger called throughout the training process.
Definition learningAgent.h:100
virtual void trainOneGeneration(uint64_t generationNumber, bool doPopulate=true)
Train the TPGGraph for one generation.
Definition learningAgent.cpp:309
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:109
virtual ~LearningAgent()=default
Default destructor for polymorphism.
Mutator::RNG & getRNG()
Getter for the RNG used by the LearningAgent.
Definition learningAgent.cpp:73
std::shared_ptr< TPG::TPGGraph > tpg
TPGGraph built during the learning process.
Definition learningAgent.h:82
std::shared_ptr< Selector::Selector > getSelector()
Getter for the Selector built by the LearningAgent.
Definition learningAgent.cpp:58
Environment env
Environment for executing Program of the LearningAgent.
Definition learningAgent.h:73
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:128
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:409
const Environment & getEnvironment() const
Accessor to the Environment of the TPGGraph.
Definition learningAgent.cpp:68
Interface for creating a Learning Environment.
Definition learningEnvironment.h:81
Learning Agent logger class that will be called during LearningAgent executions.
Definition laLogger.h:66
Definition rng.h:52
Definition tpgExecutionEngine.h:57
Factory for creating all elements constituting a TPG.
Definition tpgFactory.h:71
Class for storing a Tangled-Program-Graph.
Definition tpgGraph.h:58
Abstract class representing the vertices of a TPGGraph.
Definition tpgVertex.h:55
Definition classificationLearningEnvironment.h:44
LearningMode
Different modes in which the LearningEnvironment can be reset.
Definition learningEnvironment.h:59
Definition mapElitesArchiveLogger.h:45
Structure for simplifying the transmission of LearningParameters to functions.
Definition learningParameters.h:56