google-research
54 строки · 1.5 Кб
1# coding=utf-8
2# Copyright 2024 The Google Research Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Random Controller that proposes random topologies."""
17
18import pyglove as pg
19from es_enas.controllers import base_controller
20
21
22class RandomController(base_controller.BaseController):
23"""Random Search Controller."""
24
25def __init__(self, dna_spec, batch_size,
26**kwargs):
27"""Initialization. See base class for more details."""
28super().__init__(dna_spec, batch_size)
29del kwargs
30
31def propose_dna(self):
32"""Proposes a topology dna using stored template.
33
34Args: None.
35
36Returns:
37dna: A proposed dna.
38"""
39return pg.random_dna(self._dna_spec)
40
41def collect_rewards_and_train(self, reward_vector, dna_list):
42"""Collects rewards and sends them to the replay buffer.
43
44Args:
45reward_vector: list of reward floats.
46dna_list: list of dna's from the proposal function.
47
48Returns:
49None.
50"""
51
52del reward_vector
53del dna_list
54pass
55