Collecting data from different types of agents (agenttype_reporters)
Hi,
I am not sure if I am misunderstanding the usage of agenttype_reporters parameter in DataCollector() function, but I cannot make it work. For example, I was trying to implement it in the Money Model (https://mesa.readthedocs.io/latest/tutorials/2_collecting_data.html) by replacing
self.datacollector = mesa.DataCollector(
model_reporters={"Gini": compute_gini},
agent_reporters={"Wealth": "wealth"}
)
with
self.datacollector = mesa.DataCollector(
model_reporters={"Gini": compute_gini},
agenttype_reporters={MoneyAgent: {'Wealth': 'wealth'}}
)
In this case no errors are popping up, but at the end there are no Wealth data in the results. Running using batch_run():
params = {"width": 10, "height": 10, "n": range(5, 105, 5)}
results = mesa.batch_run(
MoneyModel,
parameters=params,
iterations=5,
max_steps=100,
number_processes=1,
data_collection_period=-1,
display_progress=True,
)
results_df = pd.DataFrame(results)
Am I missing something? If I use both agent_reporters and agenttype_reporters at the same time, then only measures defined in agent_reporters are saved in the results. Mesa version 3.2.0
Thank you!
Thanks for reporting this potential issue!
Could you try if it does collect data when not running with batch_run?
Good point, I haven't checked that. The following code works fine:
model = MoneyModel(100, 10, 10)
for _ in range(100):
model.step()
model.datacollector.get_agenttype_vars_dataframe(agent_type=MoneyAgent)
It appears that the problem lies with batch_run. Perhaps there are some alternative options to save the data from specific agent types in batch_run (to avoid saving data for all the agents you don't need)?
I would like to work on this issue, looking forward to solve.