{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Foraging toolkit demo - communicating foragers, Part I (simulation)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Outline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* [Introduction](#introduction)\n", "* [Simulation Setup](#simulation-setup)\n", "* [The Simulation Algorithm](#the-simulation-algorithm)\n", "* [Optional - Weak Communicators](#optional---weak-communicators-simulation)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In a multi-agent context, communication of information between foragers is an important\n", "feature of group-level behavior, as is the impact of different environmental conditions. We thus explore how one\n", "might infer to what extent agents communicate with each other to facilitate foraging. We ask whether the\n", "benefit of communicating information would be different for different environments, using multiple simulations\n", "with a range of communication-related hyper-parameters. In environments where food is highly clustered, it\n", "takes longer for birds to find food, but in all environments, using information communicated from other birds\n", "improves foraging success. The Bayesian inference methods are able to correctly compare the extent to which\n", "simulated agents communicate about the locations of the rewards.\n", "\n", "The communicating foragers demo is divided into two notebooks:\n", "\n", "1. Simulation (this one)\n", "2. Inference [communicators_inference.ipynb](./communicators_inference.ipynb) - proceed there after completing this notebook\n", "\n", "The users are advised to read through the demo notebooks in [docs/foraging/random-hungry-followers](../random-hungry-followers/) folder to get familiarized with the foraging toolkit.\n", "\n", "The main reference is [1], in particular Fig.3.\n", "\n", "---\n", "\n", "[1] R. Urbaniak, M. Xie, and E. Mackevicius, “Linking cognitive strategy, neural mechanism, and movement statistics in group foraging behaviors,” Sci Rep, vol. 14, no. 1, p. 21770, Sep. 2024, [doi: 10.1038/s41598-024-71931-0.](https://www.nature.com/articles/s41598-024-71931-0)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import logging\n", "import os\n", "from itertools import product\n", "\n", "import numpy as np\n", "import pandas as pd\n", "import plotly.io as pio\n", "\n", "import collab.foraging.communicators as com\n", "import collab.foraging.toolkit as ft\n", "from collab.utils import find_repo_root\n", "\n", "pio.renderers.default = \"notebook\"\n", "\n", "repo_root = find_repo_root()\n", "\n", "logging.basicConfig(level=logging.INFO, format=\"%(asctime)s %(message)s\")\n", "\n", "# if you need to change the number of frames, replace 50 with your desired number\n", "\n", "# this is an alternative continuous development setup\n", "# for automated notebook testing\n", "# feel free to ignore this\n", "dev_mode = False # set to True if you want to generate your own csvs\n", "smoke_test = \"CI\" in os.environ\n", "N_frames = 10 if smoke_test else 50" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulation setup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We simulate grid world environments with food patches of varying degrees of spatial clustering, controlling for the total amount of food in the environment. In each environment, there were 12 total food items, distributed randomly in patches of size $1 \\times 1,2 \\times 2$, or $4 \\times 4$.\n", "\n", "We parameterize the extent to which agents share information about food locations. In these simulations, agents follow a policy to select action $A_{\\text{opt}}=\\arg \\max _A(V(T(A, S)))$, where $V$ computes the expected future value based on an estimate of expected reward includes both food that they can directly observe (within a radius of 5 steps), as well as perceiving other birds eating at farther locations, and $T$ is a state transition function. In the real world, this estimate could be achieved by observing other birds and/or listening to their calls. The weighting of social information (reward locations communicated by other birds), compared to individually observed information, is given by the **communication parameter**, (`c_trust` below) which ranges from 0 (no communication) to 1 (full reliance on social information).\n", "\n", "As we shall see below, birds that communicate appear to navigate more directly to food locations than birds that search independently." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we define parameters of the forward model. We have two simulations, where `c_trust` was set either to $0$ (no communication) or $0.6$. We save the parameters for each simulation, as well as the meta-data for all simulations, in CSV files in the `data` directory." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | c_trust | \n", "sight_radius | \n", "reward_patch_dim | \n", "sim index | \n", "
---|---|---|---|---|
0 | \n", "0.0 | \n", "5 | \n", "4 | \n", "0 | \n", "
1 | \n", "0.6 | \n", "5 | \n", "4 | \n", "1 | \n", "
\n", " | c_trust | \n", "sight_radius | \n", "reward_patch_dim | \n", "sim index | \n", "
---|---|---|---|---|
0 | \n", "0.000 | \n", "5 | \n", "1 | \n", "0 | \n", "
1 | \n", "0.000 | \n", "5 | \n", "2 | \n", "1 | \n", "
2 | \n", "0.000 | \n", "5 | \n", "4 | \n", "2 | \n", "
3 | \n", "0.005 | \n", "5 | \n", "1 | \n", "3 | \n", "
4 | \n", "0.005 | \n", "5 | \n", "2 | \n", "4 | \n", "
... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
295 | \n", "0.680 | \n", "5 | \n", "2 | \n", "295 | \n", "
296 | \n", "0.680 | \n", "5 | \n", "4 | \n", "296 | \n", "
297 | \n", "0.690 | \n", "5 | \n", "1 | \n", "297 | \n", "
298 | \n", "0.690 | \n", "5 | \n", "2 | \n", "298 | \n", "
299 | \n", "0.690 | \n", "5 | \n", "4 | \n", "299 | \n", "
300 rows × 4 columns
\n", "