google-research

Форк
0
/
generator_test_util.cc 
83 строки · 2.8 Кб
1
// Copyright 2024 The Google Research Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
#include "generator_test_util.h"
16

17
#include "random_generator.h"
18
#include "absl/memory/memory.h"
19

20
namespace automl_zero {
21

22
using ::absl::make_unique;
23
using ::std::mt19937;  // NOLINT
24
using ::std::shared_ptr;
25
using ::std::vector;
26

27
Algorithm SimpleNoOpAlgorithm() {
28
  Generator generator(NO_OP_ALGORITHM,                         // Irrelevant.
29
                      6,                                  // setup_size_init
30
                      3,                                  // predict_size_init
31
                      9,                                  // learn_size_init
32
                      {}, {}, {}, nullptr, nullptr);  // Irrelevant.
33
  return generator.NoOp();
34
}
35

36
Algorithm SimpleRandomAlgorithm() {
37
  mt19937 bit_gen;
38
  RandomGenerator rand_gen(&bit_gen);
39
  Generator generator(
40
      RANDOM_ALGORITHM,  // Irrelevant.
41
      6,  // setup_size_init
42
      3,  // predict_size_init
43
      9,  // learn_size_init
44
      {SCALAR_SUM_OP, MATRIX_VECTOR_PRODUCT_OP, VECTOR_MEAN_OP},
45
      {SCALAR_SUM_OP, MATRIX_VECTOR_PRODUCT_OP, VECTOR_MEAN_OP},
46
      {SCALAR_SUM_OP, MATRIX_VECTOR_PRODUCT_OP, VECTOR_MEAN_OP},
47
      &bit_gen,
48
      &rand_gen);
49
  return generator.Random();
50
}
51

52
Algorithm SimpleGz() {
53
  Generator generator(NO_OP_ALGORITHM, 0, 0, 0, {}, {}, {}, nullptr, nullptr);
54
  return generator.LinearModel(kDefaultLearningRate);
55
}
56

57
Algorithm SimpleGrTildeGrWithBias() {
58
  Generator generator(NO_OP_ALGORITHM, 0, 0, 0, {}, {}, {}, nullptr, nullptr);
59
  return generator.NeuralNet(
60
      kDefaultLearningRate, kDefaultInitScale, kDefaultInitScale);
61
}
62

63
void SetIncreasingDataInComponentFunction(
64
    vector<shared_ptr<const Instruction>>* component_function) {
65
  for (IntegerT position = 0;
66
    position < component_function->size();
67
    ++position) {
68
    auto instruction =
69
        make_unique<Instruction>(*(*component_function)[position]);
70
    instruction->SetIntegerData(position);
71
    (*component_function)[position].reset(instruction.release());
72
  }
73
}
74

75
Algorithm SimpleIncreasingDataAlgorithm() {
76
  Algorithm algorithm = SimpleNoOpAlgorithm();
77
  SetIncreasingDataInComponentFunction(&algorithm.setup_);
78
  SetIncreasingDataInComponentFunction(&algorithm.predict_);
79
  SetIncreasingDataInComponentFunction(&algorithm.learn_);
80
  return algorithm;
81
}
82

83
}  // namespace automl_zero
84

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.