forked from google-research/google-research
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomizer.h
77 lines (63 loc) · 2.55 KB
/
randomizer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2021 The Google Research Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef AUTOML_ZERO_RANDOMIZER_H_
#define AUTOML_ZERO_RANDOMIZER_H_
#include <memory>
#include <random>
#include "definitions.h"
#include "instruction.pb.h"
namespace automl_zero {
class RandomGenerator;
class Algorithm;
// A class to randomize Algorithms. Used for Algorithm mutation and
// Algorithm generation.
class Randomizer {
public:
Randomizer(
// Ops that can be introduced into the setup component function.
// Empty means the component function is not randomized.
std::vector<Op> allowed_setup_ops,
// Ops that can be introduced into the predict component function.
// Empty means the component function is not randomized.
std::vector<Op> allowed_predict_ops,
// Ops that can be introduced into the learn component function.
// Empty means the component function is not randomized.
std::vector<Op> allowed_learn_ops,
std::mt19937* bit_gen,
RandomGenerator* rand_gen);
// Randomizes the entire Algorithm (all three component functions).
// Does not change the component function sizes.
void Randomize(Algorithm* algorithm);
// Randomizes all the instructions in the setup component function.
// Does not change the component function size.
void RandomizeSetup(Algorithm* algorithm);
// Randomizes all the instructions in the predict component function.
// Does not change the component function size.
void RandomizePredict(Algorithm* algorithm);
// Randomizes all the instructions in the learn component function.
// Does not change the component function size.
void RandomizeLearn(Algorithm* algorithm);
// Return operations to introduce into the component functions.
Op SetupOp();
Op PredictOp();
Op LearnOp();
private:
const std::vector<Op> allowed_setup_ops_;
const std::vector<Op> allowed_predict_ops_;
const std::vector<Op> allowed_learn_ops_;
std::mt19937* bit_gen_;
RandomGenerator* rand_gen_;
};
} // namespace automl_zero
#endif // AUTOML_ZERO_RANDOMIZER_H_