clement-moulin-frier / vivarium

MIT License
6 stars 0 forks source link

Add a proximity map raw sensor #76

Closed clement-moulin-frier closed 6 months ago

clement-moulin-frier commented 7 months ago

Description

This PR adds the possibility to access a raw proximity map for each agent. Proximity maps are stored in AgentState.proximity_map_dist and AgentState.proximity_map_theta, which are both of shape (max_agents, max_entities). (edit: actually I think it is (max_agents, nb_neighbors), which is the same if neighbor_radius is the size of the map, to check). The first one indicates the relative distances from all agents to all entities, the second one indicates the relative orientations. For example, AgentState.proximity_map_theta[i, j] is the orientation of entity j relative to agent i (i.e. as perceived by agent i, therefore depending on its current front direction).

This is propagated to the client side in the Configs. For example, using the NotebookController, you can access the proximity maps of agent i with controller.agents[i].proximity_map_dist and controller.agents[i].proximity_map_theta. Here, both maps are of shape (n_entities,), because they are relative a single agent i. For example, controller.agents[i].proximity_map_dist[j] is the distance of agent i to entity j.

The proximity maps will be useful for:

However it might introduce a scaling issue, see #78

Related Issue (if applicable)

Closes #7 Opens #77 #78

How to Test

Launch the server

python3 scripts/run_server.py

Launch the Panel interface

panel serve scripts/run_interface.py --autoreload

Check that agents behaves as expected, because now the prox activations are computed from these proximity maps. I.e. check that aggression, fear, shy, love works correctly.

Then, in a Jupyter notebook, check that the proximity map values are consistent wrt to the relative agent positions. For this, you can first set the behavior of agents to noop, so that they don't move. Then you can use this code in the notebook:

from vivarium.controllers.notebook_controller import NotebookController
controller = NotebookController()

ag_id = 4
ag = controller.agents[ag_id]

# Pull state from server (to do each time the state changes)
controller.update_state()
controller.pull_configs()

# To access the distance map
ag.proximity_map_dist

# To access the relative orientation map 
ag.proximity_map_theta

Check that values in the distance and orientation maps are consistent with the relative positions of the agents in the interface. For example, if entity j is on the left of agent i, then controller.agents[i].proximity_map_theta[j]should be roughly equal to pi / 4(modulo 2.pi).

I haven't tested how it behave if some agents/entities do not exist, please check this as well.

Will be also useful to test with a smaller simualtor_state.neighbor_radius to see if rebuilding the neigbor matrix doesn't break it.

Screenshots (if applicable)