mirror of
https://github.com/wassname/DeepRL.git
synced 2026-10-30 12:50:27 +08:00
Timestep based test scheme
This commit is contained in:
1 parent
de478faf9b
commit
08d45b9284
6 files changed
+46
-19
No files matched your search
+21
-2
@@ -5,10 +5,11 @@
|
||||
#######################################################################
|
||||
|
||||
import torch
|
||||
import numpy as np
|
||||
|
||||
class BaseAgent:
|
||||
def __init__(self):
|
||||
pass
|
||||
self.testing = False
|
||||
|
||||
def close(self):
|
||||
if hasattr(self.task, 'close'):
|
||||
@@ -19,4 +20,22 @@ class BaseAgent:
|
||||
|
||||
def load(self, filename):
|
||||
state_dict = torch.load(filename, map_location=lambda storage, loc: storage)
|
||||
self.network.load_state_dict(state_dict)
|
||||
self.network.load_state_dict(state_dict)
|
||||
|
||||
def deterministic_test(self):
|
||||
if self.testing:
|
||||
return
|
||||
if not self.config.test_interval:
|
||||
return
|
||||
if self.total_steps % self.config.test_interval:
|
||||
return
|
||||
if not hasattr(self, 'episode'):
|
||||
return
|
||||
rewards = []
|
||||
self.testing = True
|
||||
for _ in range(self.config.test_repetitions):
|
||||
rewards.append(self.episode(deterministic=True))
|
||||
self.testing = False
|
||||
self.config.logger.info('%d deterministic episodes: %f(%f)' % (
|
||||
self.config.test_repetitions, np.mean(rewards), np.std(rewards) / np.sqrt(len(rewards))
|
||||
))
|
||||
Reference in new issue
Block a user