Foraging toolkit demo - random, hungry and followers

Users of the foraging toolkit are interested in analyzing animal movement data, with the goal of determining what factors contribute to each agent’s decisions of where to move.

In this notebook, we consider two possible factors that may influence agents’ decisions: proximity to other agents, and closeness to food. Each factor has an associated score that is computed at each location where an agent might move. These scores are used as derived predictors in a statistical model of agents’ movements.

The fit coefficients of these derived predictor scores can be interpreted as how predictive each factor is of agents’ movement decisions.

We consider three distinct groups of foragers, each one simulated in a separate notebook. 1. Random foragers - random_foragers.ipynb 2. Hungry foragers - hungry_foragers.ipynb 3. Follower foragers - follower_foragers.ipynb

Please refer to those notebooks for more details. Running them will show and save the results in data files which are loaded below. Here we compare the resulting predictor coefficient posterior distributions.

[1]:
import os

import dill
import plotly.express as px
import plotly.io as pio

pio.renderers.default = "notebook"

import pandas as pd
[2]:
results_data_files = {
    "random": os.path.join("sim_data", "random_foragers_samples.dill"),
    "hungry": os.path.join("sim_data", "hungry_foragers_samples.dill"),
    "follower": os.path.join("sim_data", "follower_foragers_samples.dill"),
}

results_data = {"prox": [], "food": [], "group": []}
prox_axis_key = "weight_continuous_proximity_scaled_nextStep_sublinear"
food_axis_key = "weight_continuous_food_scaled_nextStep_sublinear"

for group, fname in results_data_files.items():
    with open(fname, "rb") as f:
        results_group = dill.load(f)
    results_data["prox"].extend(results_group[prox_axis_key])
    results_data["food"].extend(results_group[food_axis_key])
    results_data["group"].extend([group] * len(results_group[food_axis_key]))

resultsDF = pd.DataFrame(results_data)

resultsDF.head(), resultsDF.group.unique()
[2]:
(       prox      food   group
 0  0.008944 -0.019085  random
 1  0.002770 -0.015107  random
 2  0.033591 -0.026782  random
 3  0.043508 -0.036160  random
 4  0.019532 -0.033703  random,
 array(['random', 'hungry', 'follower'], dtype=object))
[3]:
title = "Coefficients for three bird types"
xrange = [-0.1, 0.45]
yrange = [-0.5, 1.0]

fig = px.scatter(
    resultsDF, title=title, color="group", x="prox", y="food", template="presentation"
)
fig.update_xaxes(range=[xrange[0], xrange[1]], showgrid=False)
fig.update_yaxes(range=[yrange[0], yrange[1]], showgrid=False)

fig.update_layout(autosize=False, width=600, height=600)

fig.update_traces(marker=dict(size=12, opacity=0.1))
fig.update_layout(legend=dict(yanchor="top", y=1.05, xanchor="right", x=0.97))
fig.show()
/home/rafal/miniconda3/envs/collab/lib/python3.10/site-packages/plotly/express/_core.py:2065: FutureWarning:

When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group in a future version of pandas. Pass `(name,)` instead of `name` to silence this warning.

As expected, the random group does not exhibit any significant follower/hungry behaviour; the hungry foragers are primarily driven by food proximity, and the followers’ group is mainly influenced by proximity to other agents.