GEGELATI
Loading...
Searching...
No Matches
parallelLearningAgent.h
1
39#ifndef PARALLEL_LEARNING_AGENT
40#define PARALLEL_LEARNING_AGENT
41
42#include <mutex>
43#include <queue>
44#include <thread>
45
46#include "instructions/set.h"
47#include "tpg/tpgExecutionEngine.h"
48
49#include "learn/evaluationResult.h"
50#include "learn/job.h"
51#include "learn/learningAgent.h"
52#include "learn/learningEnvironment.h"
53#include "learn/learningParameters.h"
54
55namespace Learn {
67 {
68 protected:
83 virtual void evaluateAllRootsInParallel(
84 uint64_t generationNumber, LearningMode mode,
85 std::multimap<std::shared_ptr<EvaluationResult>,
86 const TPG::TPGVertex*>& results);
87
103 uint64_t generationNumber, LearningMode mode,
104 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
105 std::shared_ptr<Job>>>&
106 resultsPerJobMap,
107 std::map<uint64_t, Archive*>& archiveMap);
108
125 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
126 std::shared_ptr<Job>>>&
127 resultsPerJobMap,
128 std::multimap<std::shared_ptr<EvaluationResult>,
129 const TPG::TPGVertex*>& results,
130 std::map<uint64_t, Archive*>& archiveMap);
131
158 uint64_t generationNumber, LearningMode mode,
159 std::queue<std::shared_ptr<Learn::Job>>& jobsToProcess,
160 std::mutex& rootsToProcessMutex,
161 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
162 std::shared_ptr<Job>>>&
163 resultsPerRootMap,
164 std::mutex& resultsPerRootMapMutex,
165 std::map<uint64_t, Archive*>& archiveMap,
166 std::mutex& archiveMapMutex, bool useMainEnvironment);
167
179 void mergeArchiveMap(std::map<uint64_t, Archive*>& archiveMap);
180
181 public:
195 LearningEnvironment& le, const Instructions::Set& iSet,
196 const LearningParameters& p,
197 const TPG::TPGFactory& factory = TPG::TPGFactory())
198 : LearningAgent(le, iSet, p, factory)
199 {
200 // overriding the maxNbThreads that basic LA defined to 1
202 };
203
222 std::multimap<std::shared_ptr<EvaluationResult>, const TPG::TPGVertex*>
223 evaluateAllRoots(uint64_t generationNumber, LearningMode mode) override;
224 };
225} // namespace Learn
226#endif
Class for storing a set of Instruction.
Definition set.h:55
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment.
Definition learningAgent.h:67
uint64_t maxNbThreads
Control the maximum number of threads when running in parallel.
Definition learningAgent.h:91
Interface for creating a Learning Environment.
Definition learningEnvironment.h:81
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment,...
Definition parallelLearningAgent.h:67
void slaveEvalJobThread(uint64_t generationNumber, LearningMode mode, std::queue< std::shared_ptr< Learn::Job > > &jobsToProcess, std::mutex &rootsToProcessMutex, std::map< uint64_t, std::pair< std::shared_ptr< EvaluationResult >, std::shared_ptr< Job > > > &resultsPerRootMap, std::mutex &resultsPerRootMapMutex, std::map< uint64_t, Archive * > &archiveMap, std::mutex &archiveMapMutex, bool useMainEnvironment)
Function implementing the behavior of slave threads during parallel evaluation of roots.
Definition parallelLearningAgent.cpp:88
virtual void evaluateAllRootsInParallelExecute(uint64_t generationNumber, LearningMode mode, std::map< uint64_t, std::pair< std::shared_ptr< EvaluationResult >, std::shared_ptr< Job > > > &resultsPerJobMap, std::map< uint64_t, Archive * > &archiveMap)
Subfunction of evaluateAllRootsInParallel which handles the creation of threads, their execution and ...
Definition parallelLearningAgent.cpp:243
virtual 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)
Subfunction of evaluateAllRootsInParallel which handles the gathering of results and the merge of the...
Definition parallelLearningAgent.cpp:281
std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > evaluateAllRoots(uint64_t generationNumber, LearningMode mode) override
Evaluate all root TPGVertex of the TPGGraph.
Definition parallelLearningAgent.cpp:53
virtual void evaluateAllRootsInParallel(uint64_t generationNumber, LearningMode mode, std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > &results)
Method for evaluating all roots with parallelism.
Definition parallelLearningAgent.cpp:225
void mergeArchiveMap(std::map< uint64_t, Archive * > &archiveMap)
Method to merge several Archive created in parallel threads.
Definition parallelLearningAgent.cpp:175
ParallelLearningAgent(LearningEnvironment &le, const Instructions::Set &iSet, const LearningParameters &p, const TPG::TPGFactory &factory=TPG::TPGFactory())
Constructor for ParallelLearningAgent.
Definition parallelLearningAgent.h:194
Factory for creating all elements constituting a TPG.
Definition tpgFactory.h:71
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
Structure for simplifying the transmission of LearningParameters to functions.
Definition learningParameters.h:56
size_t nbThreads
Number of threads (ParallelLearningAgent only)
Definition learningParameters.h:164