GEGELATI
Loading...
Searching...
No Matches
selectionMetrics.h
1
2
3#ifndef SELECTION_METRICS_H
4#define SELECTION_METRICS_H
5
6#include "learn/learningEnvironment.h"
7#include "tpg/tpgGraph.h"
8
9namespace Selector {
18 {
19 protected:
23 double score = 0;
24
33 double utility = 0;
34
35 public:
39 SelectionMetrics() = default;
40
42 virtual ~SelectionMetrics() = default;
43
50 SelectionMetrics(double score, double utility = 0)
51 : score{score}, utility{utility} {};
52
56 virtual double getScore() const;
57
61 virtual double getUtility() const;
62
72 virtual void initMetrics(
73 const TPG::TPGVertex* agent,
74 const Learn::LearningEnvironment& learningEnvironment) {
75 /* Empty because sub-class does not need to inherrit from it.*/
76 };
77
88 virtual void extractMetricsStep(
89 const TPG::TPGVertex* agent, std::vector<double> actionValues,
90 const Learn::LearningEnvironment& learningEnvironment) {
91 /* Empty because sub-class does not need to inherrit from it.*/
92 };
93
106 virtual void extractMetricsEpisode(
107 const TPG::TPGVertex* agent, size_t nbStepsExecuted,
108 const Learn::LearningEnvironment& learningEnvironment);
109
120 virtual void weightedSum(std::shared_ptr<SelectionMetrics> other,
121 size_t nbEvaluation, size_t nbEvaluationOther);
122
125 friend bool operator<(const SelectionMetrics& lhs,
126 const SelectionMetrics& rhs)
127 {
128 return lhs.getScore() < rhs.getScore();
129 }
130
140 template <class T>
141 static T weightedSum(T value, T valueOther, size_t nbEvaluation,
142 size_t nbEvaluationOther)
143 {
144 value = value * (T)nbEvaluation + valueOther * (T)nbEvaluationOther;
145 value /= (T)(nbEvaluation + nbEvaluationOther);
146 return value;
147 }
148 };
149
154 bool operator<(std::shared_ptr<SelectionMetrics> a,
155 std::shared_ptr<SelectionMetrics> b);
156
157}; // namespace Selector
158
159#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:18
static T weightedSum(T value, T valueOther, size_t nbEvaluation, size_t nbEvaluationOther)
Perform a weighted sum between 2 values.
Definition selectionMetrics.h:141
virtual void initMetrics(const TPG::TPGVertex *agent, const Learn::LearningEnvironment &learningEnvironment)
Init the metrics for the agent in the learning environment.
Definition selectionMetrics.h:72
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:26
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:88
SelectionMetrics(double score, double utility=0)
Constructor with score and utility initialization.
Definition selectionMetrics.h:50
virtual double getUtility() const
Definition selectionMetrics.cpp:9
SelectionMetrics()=default
Default constructor.
double utility
Definition selectionMetrics.h:33
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:14
friend bool operator<(const SelectionMetrics &lhs, const SelectionMetrics &rhs)
Comparison function to enable sorting of SelectionMetrics with STL.
Definition selectionMetrics.h:125
double score
Definition selectionMetrics.h:23
virtual double getScore() const
Definition selectionMetrics.cpp:4
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:40