Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
genetic_search.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include <random>
19 
21 
22 namespace tc {
23 namespace autotune {
24 
52  public:
69  const TuningConfiguration& conf,
70  size_t n,
71  uint8_t crossOverRate,
72  uint8_t mutationRate,
73  size_t numberElites);
74 
91  const std::vector<TuningConfiguration>& confs,
92  size_t n,
93  uint8_t crossOverRate,
94  uint8_t mutationRate,
95  size_t numberElites);
96 
97  void updateParameters();
98 
99  private:
100  void breed();
101 
105  TuningConfiguration&) const;
106 
107  public:
108  static constexpr int kMutateIterations = 1000;
109  static constexpr int kMinCandidatesForBreeding = 3;
110 
111  using Population = std::vector<std::unique_ptr<CandidateConfiguration>>;
112 
115  const size_t kMaxPopulationSize;
116  const uint8_t kCrossOverRate;
117  const uint8_t kMutationRate;
118  const size_t kNumberElites;
119 
120  /*
121  * c++11 seeding is (apparently) not of the highest quality:
122  * http://www.pcg-random.org/posts/cpp-seeding-surprises.html
123  * pcg-cpp seems like a good alternative:
124  * https://www.johndcook.com/blog/2017/08/14/testing-rngs-with-practrand/
125  * http://www.pcg-random.org/posts/pcg-passes-practrand.html
126  */
127  mutable std::mt19937_64 rng;
128 };
129 
130 } // namespace autotune
131 } // namespace tc
Definition: parameters.h:149
TuningConfiguration lastBestConf
Definition: genetic_search.h:114
static constexpr int kMutateIterations
Definition: genetic_search.h:108
const uint8_t kMutationRate
Definition: genetic_search.h:117
const size_t kMaxPopulationSize
Definition: genetic_search.h:115
TuningConfiguration crossover(TuningConfiguration &, TuningConfiguration &, TuningConfiguration &) const
static constexpr int kMinCandidatesForBreeding
Definition: genetic_search.h:109
const size_t kNumberElites
Definition: genetic_search.h:118
std::vector< std::unique_ptr< CandidateConfiguration >> Population
Definition: genetic_search.h:111
Population population
Definition: genetic_search.h:113
std::mt19937_64 rng
Definition: genetic_search.h:127
GeneticSearch(const TuningConfiguration &conf, size_t n, uint8_t crossOverRate, uint8_t mutationRate, size_t numberElites)
Definition: genetic_search.h:51
const uint8_t kCrossOverRate
Definition: genetic_search.h:116