HPCC2025/Duel_Double_DQN/utils.py

33 lines
1006 B
Python
Raw Normal View History

2025-03-19 20:40:35 +08:00
import numpy as np
2025-03-18 21:16:48 +08:00
def evaluate_policy(env, agent, turns = 3):
total_scores = 0
for j in range(turns):
s = env.reset()
done = False
2025-03-19 20:40:35 +08:00
action_series = []
2025-03-18 21:16:48 +08:00
while not done:
# Take deterministic actions at test time
a = agent.select_action(s, deterministic=True)
s_next, r, dw, tr, info = env.step(a)
done = (dw or tr)
2025-03-19 20:40:35 +08:00
action_series.append(a)
2025-03-18 21:16:48 +08:00
total_scores += r
s = s_next
print('action series: ', np.round(action_series, 3))
2025-03-19 20:40:35 +08:00
print('state: ', s)
2025-03-18 21:16:48 +08:00
return int(total_scores/turns)
#You can just ignore this funciton. Is not related to the RL.
def str2bool(v):
'''transfer str to bool for argparse'''
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'True','true','TRUE', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'False','false','FALSE', 'f', 'n', '0'):
return False
else:
print('Wrong Input.')
raise