-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptimizers.py
More file actions
33 lines (27 loc) · 791 Bytes
/
optimizers.py
File metadata and controls
33 lines (27 loc) · 791 Bytes
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
"""
Optimizers for the A3C algorithm.
"""
import threading
import time
from brain import brain
class Optimizer(threading.Thread):
"""
An independent unit in charge of optimizing the actor-critic model.
"""
def __init__(self):
super().__init__()
self.started = False
def run(self):
"""
Start the optimizer. It will start optimizing until explicitly stopped.
"""
self.started = True
while self.started:
if not brain.run_optimization_step():
# If list is empty, don't keep trying until timeout, just yield already
time.sleep(0)
def stop(self):
"""
Stop the agent. It will stop trying to optimize the brain.
"""
self.started = False