-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation_vs_epsilon.py
More file actions
58 lines (44 loc) · 1.88 KB
/
Copy pathsimulation_vs_epsilon.py
File metadata and controls
58 lines (44 loc) · 1.88 KB
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
import time
import numpy as np
from concurrent.futures import ProcessPoolExecutor
import pandas as pd
import common as cmn
from simulation_vs_theta_voi_unaware import run_episode
if __name__ == '__main__':
# Parse arguments, if any
parallel, data_folder, _, overwrite = cmn.common_parser()
### MAIN SIMULATION PARAMETERS ###
theta = cmn.std_theta
epsilon_vec = cmn.epsilon_vec
num_frame = cmn.num_frame
# Check if files exist and load it if there
prefix = 'vs_epsilon'
data_shape = (len(epsilon_vec), len(cmn.results_label))
avg_results, filename = cmn.check_data(data_shape, prefix, data_folder, overwrite_flag=overwrite)
# Start evaluating
for m, epsilon in enumerate(epsilon_vec):
# Check if data is there
if overwrite or np.any(np.isnan(avg_results[m])):
args = (theta, epsilon, num_frame)
start_time = time.time()
if parallel:
with ProcessPoolExecutor() as executor:
futures = [executor.submit(run_episode, ep, *args) for ep in range(cmn.E)]
results = [f.result() for f in futures]
else:
results = []
for ep in range(cmn.E):
print(f'\tEpisode: {ep:02d}/{cmn.E - 1:02d}')
results.append(run_episode(ep, *args))
# Average the results
avg_results[m] = np.mean(np.array(results), axis=0)
# Save data (doing it every time is redundant, but it is safe)
avg_df = pd.DataFrame(avg_results, columns=cmn.results_label)
avg_df.insert(0, 'epsilon', epsilon_vec)
avg_df.to_csv(filename, index=False)
# Print time
elapsed = time.time() - start_time
print(f"\t...done in {elapsed:.3f} seconds")
else:
print("\t...already done!")
continue