GEGELATI
Loading...
Searching...
No Matches
selectionMetrics.h
1
37#ifndef SELECTION_METRICS_H
38#define SELECTION_METRICS_H
39
40#include "learn/learningEnvironment.h"
41#include "tpg/tpgGraph.h"
42
43namespace Selector {
52 {
53 protected:
57 double score = 0;
58
67 double utility = 0;
68
69 public:
73 SelectionMetrics() = default;
74
76 virtual ~SelectionMetrics() = default;
77
84 SelectionMetrics(double score, double utility = 0)
85 : score{score}, utility{utility} {};
86
90 virtual double getScore() const;
91
95 virtual double getUtility() const;
96
106 virtual void initMetrics(
107 const TPG::TPGVertex* agent,
108 const Learn::LearningEnvironment& learningEnvironment) {
109 /* Empty because sub-class does not need to inherrit from it.*/
110 };
111
122 virtual void extractMetricsStep(
123 const TPG::TPGVertex* agent, std::vector<double> actionValues,
124 const Learn::LearningEnvironment& learningEnvironment) {
125 /* Empty because sub-class does not need to inherrit from it.*/
126 };
127
140 virtual void extractMetricsEpisode(
141 const TPG::TPGVertex* agent, size_t nbStepsExecuted,
142 const Learn::LearningEnvironment& learningEnvironment);
143
154 virtual void weightedSum(std::shared_ptr<SelectionMetrics> other,
155 size_t nbEvaluation, size_t nbEvaluationOther);
156
159 friend bool operator<(const SelectionMetrics& lhs,
160 const SelectionMetrics& rhs)
161 {
162 return lhs.getScore() < rhs.getScore();
163 }
164
174 template <class T>
175 static T weightedSum(T value, T valueOther, size_t nbEvaluation,
176 size_t nbEvaluationOther)
177 {
178 value = value * (T)nbEvaluation + valueOther * (T)nbEvaluationOther;
179 value /= (T)(nbEvaluation + nbEvaluationOther);
180 return value;
181 }
182 };
183
188 bool operator<(std::shared_ptr<SelectionMetrics> a,
189 std::shared_ptr<SelectionMetrics> b);
190
191}; // namespace Selector
192
193#endif // SELECTION_METRICS_H
Interface for creating a Learning Environment.
Definition learningEnvironment.h:81
Class to extract metrics from either the agent or the environment.
Definition selectionMetrics.h:52
static T weightedSum(T value, T valueOther, size_t nbEvaluation, size_t nbEvaluationOther)
Perform a weighted sum between 2 values.
Definition selectionMetrics.h:175
virtual void initMetrics(const TPG::TPGVertex *agent, const Learn::LearningEnvironment &learningEnvironment)
Init the metrics for the agent in the learning environment.
Definition selectionMetrics.h:106
virtual void weightedSum(std::shared_ptr< SelectionMetrics > other, size_t nbEvaluation, size_t nbEvaluationOther)
Perform a weighted sum between this SelectionMetrics and another.
Definition selectionMetrics.cpp:61
virtual void extractMetricsStep(const TPG::TPGVertex *agent, std::vector< double > actionValues, const Learn::LearningEnvironment &learningEnvironment)
Extract metrics from the agent in the learning environment.
Definition selectionMetrics.h:122
SelectionMetrics(double score, double utility=0)
Constructor with score and utility initialization.
Definition selectionMetrics.h:84
virtual double getUtility() const
Definition selectionMetrics.cpp:44
SelectionMetrics()=default
Default constructor.
double utility
Definition selectionMetrics.h:67
virtual ~SelectionMetrics()=default
Default destructor.
virtual void extractMetricsEpisode(const TPG::TPGVertex *agent, size_t nbStepsExecuted, const Learn::LearningEnvironment &learningEnvironment)
Extract metrics from the agent in the learning environment.
Definition selectionMetrics.cpp:49
friend bool operator<(const SelectionMetrics &lhs, const SelectionMetrics &rhs)
Comparison function to enable sorting of SelectionMetrics with STL.
Definition selectionMetrics.h:159
double score
Definition selectionMetrics.h:57
virtual double getScore() const
Definition selectionMetrics.cpp:39
Abstract class representing the vertices of a TPGGraph.
Definition tpgVertex.h:55
Definition mapElitesArchiveLogger.h:45
bool operator<(std::shared_ptr< SelectionMetrics > a, std::shared_ptr< SelectionMetrics > b)
Comparison function to enable sorting of SelectionMetrics with STL.
Definition selectionMetrics.cpp:75