File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,45 @@ def search_efficiency(exp_data):
176
176
177
177
return effs
178
178
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
+
179
218
180
219
if __name__ == "__main__" :
181
220
import fire
You can’t perform that action at this time.
0 commit comments