GEGELATI

Loading...
Searching...
No Matches
adversarialLearningAgent.h
1
37#ifndef ADVERSARIAL_LEARNING_AGENT_H
38#define ADVERSARIAL_LEARNING_AGENT_H
39
40#include "learn/adversarialEvaluationResult.h"
41#include "learn/adversarialJob.h"
42#include "learn/adversarialLearningAgent.h"
43#include "learn/adversarialLearningEnvironment.h"
44#include "learn/parallelLearningAgent.h"
45
46 namespace Learn {
73 class AdversarialLearningAgent : public ParallelLearningAgent
74 {
75 protected:
83 std::vector<const TPG::TPGVertex*> champions;
84
88 size_t agentsPerEvaluation;
89
114 void evaluateAllRootsInParallelCompileResults(
115 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
116 std::shared_ptr<Job>>>&
117 resultsPerJobMap,
118 std::multimap<std::shared_ptr<EvaluationResult>,
119 const TPG::TPGVertex*>& results,
120 std::map<uint64_t, Archive*>& archiveMap) override;
121
122 public:
137 AdversarialLearningAgent(
138 LearningEnvironment& le, const Instructions::Set& iSet,
139 const LearningParameters& p, size_t agentsPerEval = 2,
140 const TPG::TPGFactory& factory = TPG::TPGFactory())
141 : ParallelLearningAgent(le, iSet, p, factory),
142 agentsPerEvaluation(agentsPerEval)
143 {
144 }
145
161 std::multimap<std::shared_ptr<Learn::EvaluationResult>,
162 const TPG::TPGVertex*>
163 evaluateAllRoots(uint64_t generationNumber,
164 Learn::LearningMode mode) override;
165
197 virtual std::shared_ptr<EvaluationResult> evaluateJob(
198 TPG::TPGExecutionEngine& tee, const Job& job,
199 uint64_t generationNumber, LearningMode mode,
200 LearningEnvironment& le) const override;
201
228 std::queue<std::shared_ptr<Learn::Job>> makeJobs(
229 Learn::LearningMode mode,
230 TPG::TPGGraph* tpgGraph = nullptr) override;
231
239 std::shared_ptr<Learn::Job> makeJob(const TPG::TPGVertex* vertex,
240 Learn::LearningMode mode, int idx,
241 TPG::TPGGraph* tpgGraph) override;
242 };
243} // namespace Learn
244
245#endif
Instructions::Set
Class for storing a set of Instruction.
Definition set.h:55
Learn::AdversarialLearningAgent
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment,...
Definition adversarialLearningAgent.h:74
Learn::AdversarialLearningAgent::AdversarialLearningAgent
AdversarialLearningAgent(LearningEnvironment &le, const Instructions::Set &iSet, const LearningParameters &p, size_t agentsPerEval=2, const TPG::TPGFactory &factory=TPG::TPGFactory())
Constructor for AdversarialLearningAgent.
Definition adversarialLearningAgent.h:137
Learn::AdversarialLearningAgent::makeJob
std::shared_ptr< Learn::Job > makeJob(const TPG::TPGVertex *vertex, Learn::LearningMode mode, int idx, TPG::TPGGraph *tpgGraph) override
Override of the LearningAgent::makeJob function.
Definition adversarialLearningAgent.cpp:258
Learn::AdversarialLearningAgent::evaluateAllRoots
std::multimap< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > evaluateAllRoots(uint64_t generationNumber, Learn::LearningMode mode) override
Evaluate all root TPGVertex of the TPGGraph.
Definition adversarialLearningAgent.cpp:44
Learn::AdversarialLearningAgent::agentsPerEvaluation
size_t agentsPerEvaluation
Number of agents per evaluation (e.g. 2 in tic-tac-toe).
Definition adversarialLearningAgent.h:88
Learn::AdversarialLearningAgent::evaluateAllRootsInParallelCompileResults
void evaluateAllRootsInParallelCompileResults(std::map< uint64_t, std::pair< std::shared_ptr< EvaluationResult >, std::shared_ptr< Job > > > &resultsPerJobMap, std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > &results, std::map< uint64_t, Archive * > &archiveMap) override
Subfunction of evaluateAllRootsInParallel which handles the gathering of results and the merge of the...
Definition adversarialLearningAgent.cpp:58
Learn::AdversarialLearningAgent::champions
std::vector< const TPG::TPGVertex * > champions
Champions of the last generation.
Definition adversarialLearningAgent.h:83
Learn::AdversarialLearningAgent::evaluateJob
virtual std::shared_ptr< EvaluationResult > evaluateJob(TPG::TPGExecutionEngine &tee, const Job &job, uint64_t generationNumber, LearningMode mode, LearningEnvironment &le) const override
Evaluates policy starting from the given root, taking adversarial in charge.
Definition adversarialLearningAgent.cpp:127
Learn::AdversarialLearningAgent::makeJobs
std::queue< std::shared_ptr< Learn::Job > > makeJobs(Learn::LearningMode mode, TPG::TPGGraph *tpgGraph=nullptr) override
Puts all roots into AdversarialJob to be able to use them in simulation later. The difference with th...
Definition adversarialLearningAgent.cpp:183
Learn::Job
This class embeds roots for the simulations.
Definition job.h:53
Learn::LearningEnvironment
Interface for creating a Learning Environment.
Definition learningEnvironment.h:81
Learn::ParallelLearningAgent
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment,...
Definition parallelLearningAgent.h:66
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 adversarialEvaluationResult.h:45
Learn::LearningMode
LearningMode
Different modes in which the LearningEnvironment can be reset.
Definition learningEnvironment.h:59
Learn::LearningParameters
Structure for simplifying the transmission of LearningParameters to functions.
Definition learningParameters.h:54