Skip to content

Commit c31b585

Browse files
committed
Patch score update
score.py
1 parent 2bcd7b7 commit c31b585

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

explorationlib/score.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,45 @@ def search_efficiency(exp_data):
176176

177177
return effs
178178

179+
def on_off_patch_time(exp_data, num_agents, patch_locs, patch_radius):
180+
"""Time steps within vs between patches for multiple runs"""
181+
182+
# Load?
183+
if isinstance(exp_data, str):
184+
exp_data = load(exp_data)
185+
186+
on_patch_steps = []
187+
off_patch_steps = []
188+
189+
var_name="exp_state"
190+
191+
for log in tqdm(exp_data, desc="on_off_patch_time"):
192+
193+
on_patch_step = 0
194+
off_patch_step = 0
195+
196+
# fmt
197+
states_vec = log[var_name]
198+
states = [list() for _ in range(num_agents)]
199+
200+
# repack
201+
states = np.array(states_vec)
202+
203+
xs = states[:, 0]
204+
ys = states[:, 1]
205+
206+
for x, y in zip(xs, ys):
207+
for patch_loc in patch_locs:
208+
if (x - patch_loc[0])**2 + (y - patch_loc[1])**2 < patch_radius:
209+
on_patch_step += 1
210+
else:
211+
off_patch_step += 1
212+
213+
on_patch_steps.append(on_patch_step)
214+
off_patch_steps.append(off_patch_step)
215+
216+
return on_patch_steps, off_patch_steps
217+
179218

180219
if __name__ == "__main__":
181220
import fire

0 commit comments

Comments
 (0)