-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesting.py
146 lines (108 loc) · 5.16 KB
/
testing.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from agent import *
from funcs import *
from config import *
import config
from game import *
import loggers as lg
import random
from model import Residual_CNN
import initialise
import pickle
from settings import run_folder, run_archive_folder
from memory import Memory
import sys
import numpy as np
"""seed = 808 # np.random.random_integers(0,5000)
#print(seed)
np.random.seed(seed=seed)
py_seed = 967 #random.randint(0,1000)
#print("Python seed: {0}".format(py_seed))
random.seed(py_seed)"""
#arg = sys.argv[1]
arg = 'rollout_test'
game = Game()
if arg == "output_eval":
memories = []
if initialise.INITIAL_MEMORY_VERSION == [None] * DECISION_TYPES:
for i in range(DECISION_TYPES):
memories.append(Memory(MEMORY_SIZE[i]))
else:
for d_t, MEM_VERSION in enumerate(initialise.INITIAL_MEMORY_VERSION):
print('LOADING MEMORY VERSION ' + str(MEM_VERSION) + '...')
memories.append(pickle.load(open(
run_archive_folder + game.name + '/run' + str(initialise.INITIAL_RUN_NUMBER).zfill(4) + "/memory/decision_" + str(d_t) + "_memory" + str(MEM_VERSION).zfill(4) + ".p", "rb")))
if memories[-1].MEMORY_SIZE < MEMORY_SIZE[d_t]:
memories[-1].extension(MEMORY_SIZE[d_t])
nn = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, game.grid_shape, PLAYER_COUNT,
config.HIDDEN_CNN_LAYERS, 0)
m_tmp = nn.read(game.name, initialise.INITIAL_RUN_NUMBER, initialise.INITIAL_MODEL_VERSION[0])
nn.model.set_weights(m_tmp.get_weights())
trained_agent = Agent('trained_agent', game.action_size, config.MCTS_SIMS, config.CPUCT, [nn])
trained_agent.evaluate_accuracy(memories[0].ltmemory, 0)
quit()
if arg == "pred_test":
nn = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, (1,) + game.grid_shape, [1],\
config.HIDDEN_CNN_LAYERS, 0)
player = Agent('player', game.state_size, config.MCTS_SIMS, config.CPUCT, [nn])
print(player.predict_value(game.gameState))
exit()
import sys, os
import logging
logging.basicConfig(
level=logging.DEBUG, # DEBUG here
format='%(asctime)s %(levelname)s %(message)s',
filename='svn2ftp.debug.log',
filemode='a'
)
console = logging.StreamHandler()
console.setLevel(logging.ERROR) # ERROR here
logging.getLogger('').addHandler(console)
if arg == "rollout_test":
rollout_agent = testing_agent(MCTS_SIMS, 'trained_agent')
random_agent = User('random_agent')
if PLAYER_COUNT == 2:
version_tournament([rollout_agent, random_agent], 1000, lg.logger_tourney)
else:
version_tournament([rollout_agent, random_agent, rollout_agent, random_agent], 100, lg.logger_tourney)
if arg == "nn_test":
nn = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, game.grid_shape, PLAYER_COUNT,
config.HIDDEN_CNN_LAYERS, 0)
m_tmp = nn.read(game.name, initialise.INITIAL_RUN_NUMBER, initialise.INITIAL_MODEL_VERSION[0])
nn.model.set_weights(m_tmp.get_weights())
#trained_agent = Agent('trained_agent', game.action_size, config.MCTS_SIMS, config.CPUCT, [nn])
trained_agent = testing_agent(MCTS_SIMS, 'trained_agent')
random_agent = User('random_agent')
version_tournament([trained_agent, random_agent, random_agent, random_agent], 100, lg.logger_tourney)
quit()
if arg == "base_test":
base = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, game.grid_shape, PLAYER_COUNT,
config.HIDDEN_CNN_LAYERS, 0)
nn = Residual_CNN(config.REG_CONST, config.LEARNING_RATE, game.grid_shape, PLAYER_COUNT,
config.HIDDEN_CNN_LAYERS, 0)
print("Loading model {}".format(initialise.INITIAL_MODEL_VERSION[0]))
m_tmp = nn.read(game.name, initialise.INITIAL_RUN_NUMBER, initialise.INITIAL_MODEL_VERSION[0])
nn.model.set_weights(m_tmp.get_weights())
trained_agent = Agent('trained_agent', game.action_size, config.MCTS_SIMS, config.CPUCT, [nn])
#trained_agent = testing_agent(MCTS_SIMS, 'trained_agent')
rollout_agent = testing_agent(MCTS_SIMS, 'rollout_agent')
#trained_agent.evaluate()
#untrained_agent = Agent('untrained_agent', game.action_size, config.MCTS_SIMS, config.CPUCT, [base])
#untrained_agent = testing_agent(MCTS_SIMS, 'untrained_agent')
#version_tournament([trained_agent, untrained_agent, untrained_agent, untrained_agent], 400, lg.logger_tourney)
version_tournament([rollout_agent, trained_agent, rollout_agent, trained_agent], 800, lg.logger_tourney)
quit()
randomization_test = False
if arg == "randomization_test":
count = 0
for i in range(100):
game.reset()
state = game.gameState
while not state.isEndGame:
count += 1
if len(state.allowedActions) > 1:
state, _, _ = state.takeAction(random.choice(state.allowedActions))
elif len(state.allowedActions) == 1:
state, _, _ = state.takeAction(state.allowedActions[0])
else:
state, _, _ = state.takeAction(-1)
print(count / 100)