GEGELATI
Loading...
Searching...
No Matches
parallelLearningAgent.h
1
38#ifndef PARALLEL_LEARNING_AGENT
39#define PARALLEL_LEARNING_AGENT
40
41#include <mutex>
42#include <queue>
43#include <thread>
44
45#include "instructions/set.h"
46#include "tpg/tpgExecutionEngine.h"
47
48#include "learn/evaluationResult.h"
49#include "learn/job.h"
50#include "learn/learningAgent.h"
51#include "learn/learningEnvironment.h"
52#include "learn/learningParameters.h"
53
54namespace Learn {
66 {
67 protected:
82 virtual void evaluateAllRootsInParallel(
83 uint64_t generationNumber, LearningMode mode,
84 std::multimap<std::shared_ptr<EvaluationResult>,
85 const TPG::TPGVertex*>& results);
86
102 uint64_t generationNumber, LearningMode mode,
103 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
104 std::shared_ptr<Job>>>&
105 resultsPerJobMap,
106 std::map<uint64_t, Archive*>& archiveMap);
107
124 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
125 std::shared_ptr<Job>>>&
126 resultsPerJobMap,
127 std::multimap<std::shared_ptr<EvaluationResult>,
128 const TPG::TPGVertex*>& results,
129 std::map<uint64_t, Archive*>& archiveMap);
130
157 uint64_t generationNumber, LearningMode mode,
158 std::queue<std::shared_ptr<Learn::Job>>& jobsToProcess,
159 std::mutex& rootsToProcessMutex,
160 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
161 std::shared_ptr<Job>>>&
162 resultsPerRootMap,
163 std::mutex& resultsPerRootMapMutex,
164 std::map<uint64_t, Archive*>& archiveMap,
165 std::mutex& archiveMapMutex, bool useMainEnvironment);
166
178 void mergeArchiveMap(std::map<uint64_t, Archive*>& archiveMap);
179
180 public:
194 LearningEnvironment& le, const Instructions::Set& iSet,
195 const LearningParameters& p,
196 const TPG::TPGFactory& factory = TPG::TPGFactory())
197 : LearningAgent(le, iSet, p, factory)
198 {
199 // overriding the maxNbThreads that basic LA defined to 1
201 };
202
221 std::multimap<std::shared_ptr<EvaluationResult>, const TPG::TPGVertex*>
222 evaluateAllRoots(uint64_t generationNumber, LearningMode mode) override;
223 };
224} // namespace Learn
225#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:66
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:193
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:55
size_t nbThreads
Number of threads (ParallelLearningAgent only)
Definition learningParameters.h:163