GEGELATI

Loading...
Searching...
No Matches
cvtMapElitesArchive.h
1#ifndef CVT_MAP_ELITES_ARCHIVE_H
2#define CVT_MAP_ELITES_ARCHIVE_H
3
4#include "mapElitesArchive.h"
5#include <gegelati.h>
6
7namespace Selector {
8 namespace MapElites {
9
16 class CvtMapElitesArchive : public MapElitesArchive
17 {
18 protected:
20 size_t nbCentroids;
21
23 size_t nbIterationInit;
24
26 size_t nbDotsInit;
27
29 double a1;
30
32 double b1;
33
35 double a2;
36
38 double b2;
39
41 std::vector<std::vector<double>> centroids;
42
43 public:
60 CvtMapElitesArchive(Mutator::RNG& rng, size_t nbCentroids,
61 size_t nbDescriptors, double minValue,
62 double maxValue, size_t nbIterationInit,
63 size_t nbDotsInit, double a1, double b1,
64 double a2, double b2)
65 : MapElitesArchive(0, nbDescriptors, minValue, maxValue),
66 nbCentroids{nbCentroids}, nbIterationInit{nbIterationInit},
67 nbDotsInit{nbDotsInit}, a1{a1}, b1{b1}, a2{a2}, b2{b2}
68 {
69 centroids.resize(nbCentroids);
70 archive.resize(nbCentroids);
71 initialize_cvt(rng);
72 }
73
80 double dist_squared(const std::vector<double>& a,
81 const std::vector<double>& b);
82
89 std::vector<double> add(const std::vector<double>& a,
90 const std::vector<double>& b);
91
98 std::vector<double> scalar_mult(const std::vector<double>& a,
99 double s);
100
106 std::vector<double> average(
107 const std::vector<std::vector<double>>& points);
108
114 std::vector<double> random_point(Mutator::RNG& rng);
115
122 size_t nearest(const std::vector<double>& point,
123 const std::vector<std::vector<double>>& centroids);
124
130 void initialize_cvt(Mutator::RNG& rng);
131
137 size_t getIndexForDescriptor(
138 const std::vector<double>& descriptors) const;
139
143 const std::pair<std::shared_ptr<Learn::EvaluationResult>,
144 const TPG::TPGVertex*>&
145 getArchiveFromDescriptors(
146 const std::vector<double>& descriptors) const override;
147
151 void setArchiveFromDescriptors(
152 const TPG::TPGVertex* vertex,
153 std::shared_ptr<Learn::EvaluationResult> eval,
154 const std::vector<double>& descriptors) override;
155
159 virtual const std::vector<std::vector<double>>& getCentroids()
160 const;
161 };
162 }; // namespace MapElites
163}; // namespace Selector
164
165#endif
Mutator::RNG
Definition rng.h:52
Selector::MapElites::CvtMapElitesArchive
CVT Map Elites Archive class.
Definition cvtMapElitesArchive.h:17
Selector::MapElites::CvtMapElitesArchive::nbDotsInit
size_t nbDotsInit
Number of dots for initialization.
Definition cvtMapElitesArchive.h:26
Selector::MapElites::CvtMapElitesArchive::nearest
size_t nearest(const std::vector< double > &point, const std::vector< std::vector< double > > &centroids)
Find the nearest centroid to a given point.
Definition cvtMapElitesArchive.cpp:59
Selector::MapElites::CvtMapElitesArchive::add
std::vector< double > add(const std::vector< double > &a, const std::vector< double > &b)
Vector addition.
Definition cvtMapElitesArchive.cpp:21
Selector::MapElites::CvtMapElitesArchive::getCentroids
virtual const std::vector< std::vector< double > > & getCentroids() const
Return the centroids used by the CVT.
Definition cvtMapElitesArchive.cpp:165
Selector::MapElites::CvtMapElitesArchive::b2
double b2
CVT parameters.
Definition cvtMapElitesArchive.h:38
Selector::MapElites::CvtMapElitesArchive::random_point
std::vector< double > random_point(Mutator::RNG &rng)
Generate a random point within the descriptor bounds.
Definition cvtMapElitesArchive.cpp:50
Selector::MapElites::CvtMapElitesArchive::initialize_cvt
void initialize_cvt(Mutator::RNG &rng)
Initialize the CVT centroids using Lloyd's algorithm.
Definition cvtMapElitesArchive.cpp:78
Selector::MapElites::CvtMapElitesArchive::b1
double b1
CVT parameters.
Definition cvtMapElitesArchive.h:32
Selector::MapElites::CvtMapElitesArchive::nbIterationInit
size_t nbIterationInit
Number of iterations for initialization.
Definition cvtMapElitesArchive.h:23
Selector::MapElites::CvtMapElitesArchive::centroids
std::vector< std::vector< double > > centroids
Centroids of the CVT.
Definition cvtMapElitesArchive.h:41
Selector::MapElites::CvtMapElitesArchive::dist_squared
double dist_squared(const std::vector< double > &a, const std::vector< double > &b)
Calculate squared Euclidean distance between two points.
Definition cvtMapElitesArchive.cpp:12
Selector::MapElites::CvtMapElitesArchive::CvtMapElitesArchive
CvtMapElitesArchive(Mutator::RNG &rng, size_t nbCentroids, size_t nbDescriptors, double minValue, double maxValue, size_t nbIterationInit, size_t nbDotsInit, double a1, double b1, double a2, double b2)
Constructor of the CVT Map Elites Archive.
Definition cvtMapElitesArchive.h:60
Selector::MapElites::CvtMapElitesArchive::nbCentroids
size_t nbCentroids
Number of centroids.
Definition cvtMapElitesArchive.h:20
Selector::MapElites::CvtMapElitesArchive::a2
double a2
CVT parameters.
Definition cvtMapElitesArchive.h:35
Selector::MapElites::CvtMapElitesArchive::setArchiveFromDescriptors
void setArchiveFromDescriptors(const TPG::TPGVertex *vertex, std::shared_ptr< Learn::EvaluationResult > eval, const std::vector< double > &descriptors) override
Set the archive content at given descriptors.
Definition cvtMapElitesArchive.cpp:135
Selector::MapElites::CvtMapElitesArchive::average
std::vector< double > average(const std::vector< std::vector< double > > &points)
Compute the average of a set of points.
Definition cvtMapElitesArchive.cpp:39
Selector::MapElites::CvtMapElitesArchive::scalar_mult
std::vector< double > scalar_mult(const std::vector< double > &a, double s)
Scalar multiplication.
Definition cvtMapElitesArchive.cpp:30
Selector::MapElites::CvtMapElitesArchive::getArchiveFromDescriptors
const std::pair< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > & getArchiveFromDescriptors(const std::vector< double > &descriptors) const override
Get the archive content at given descriptors.
Definition cvtMapElitesArchive.cpp:128
Selector::MapElites::CvtMapElitesArchive::a1
double a1
CVT parameters.
Definition cvtMapElitesArchive.h:29
Selector::MapElites::CvtMapElitesArchive::getIndexForDescriptor
size_t getIndexForDescriptor(const std::vector< double > &descriptors) const
Get the index for given descriptors.
Definition cvtMapElitesArchive.cpp:143
Selector::MapElites::MapElitesArchive
Class representing a Map Elites archive.
Definition mapElitesArchive.h:25
Selector::MapElites::MapElitesArchive::minValue
double minValue
Minimum value for the descriptors.
Definition mapElitesArchive.h:34
Selector::MapElites::MapElitesArchive::maxValue
double maxValue
Maximum value for the descriptors.
Definition mapElitesArchive.h:37
Selector::MapElites::MapElitesArchive::archive
std::vector< std::pair< std::shared_ptr< Learn::EvaluationResult >, const TPG::TPGVertex * > > archive
Definition mapElitesArchive.h:46
Selector::MapElites::MapElitesArchive::nbDescriptors
uint64_t nbDescriptors
Number of descriptors for this archive.
Definition mapElitesArchive.h:31
TPG::TPGVertex
Abstract class representing the vertices of a TPGGraph.
Definition tpgVertex.h:55
gegelati.h
Helper file gathering all headers from the GEGELATI lib to ease their inclusion in apps.
Selector
Definition mapElitesArchiveLogger.h:45