-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.py
executable file
·52 lines (41 loc) · 1.62 KB
/
base.py
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
from abc import abstractmethod
import numpy as np
from typing import Tuple, Union
from tools.rl_constants import Experience, ExperienceBatch, BrainSet, Action
from tools.parameter_capture import ParameterCapture
class Agent:
""" An agent which received state & reward from, and interacts with, and environment"""
def __init__(self, state_shape: Union[Tuple[int, ...], int], action_size: int):
self.state_shape = state_shape
self.action_size = action_size
self.warmup = False
self.t_step = 0
self.episode_counter = 0
self.param_capture = ParameterCapture()
self.training = True
def set_warmup(self, warmup: bool):
self.warmup = warmup
@abstractmethod
def set_mode(self, mode: str):
pass
def preprocess_state(self, state):
""" Perform any state preprocessing """
return state
@abstractmethod
def get_action(self, state: np.array, *args, **kwargs) -> Action:
"""Determine an action given an environment state"""
raise NotImplementedError
@abstractmethod
def get_random_action(self, *args, **kwargs) -> Action:
raise NotImplementedError
@abstractmethod
def step(self, experience: Experience, **kwargs) -> None:
"""Take a step in the environment, encompassing model learning and memory population"""
raise NotImplementedError
@abstractmethod
def step_episode(self, episode: int, *args) -> None:
"""Perform any end-of-episode updates"""
raise NotImplementedError
@abstractmethod
def learn(self, experience_batch: ExperienceBatch):
pass