-
Notifications
You must be signed in to change notification settings - Fork 927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
meta-agent creation #2561
meta-agent creation #2561
Conversation
Performance benchmarks:
|
- adds ability to dynamically create meta-agents - adds alliance formation model to demonstrate - adds tests to agent.py for meta agent creation
5031937
to
2b0be46
Compare
for more information, see https://pre-commit.ci
- adds ability to dynamically create meta-agents - adds alliance formation model to demonstrate - adds tests to agent.py for meta agent creation
for more information, see https://pre-commit.ci
Thanks for this PR. I need to read up a little about meta-agents to form an opinion on them. Especially what they are/aren't and do/don't. I hope to do that Sunday. |
self.datacollector = mesa.DataCollector(model_reporters={"Network": "network"}) | ||
|
||
# Create Agents | ||
power = np.random.normal(mean, std_dev, n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change this to use self.rng to get the seeded numpy random number generator
""" | ||
Calculate the Shapley value of the two agents | ||
""" | ||
other_agent.hierarchy = other_agent.hierarchy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line makes no sense to me.
Calculate the Shapley value of the two agents | ||
""" | ||
other_agent.hierarchy = other_agent.hierarchy | ||
self.hierarchy = self.hierarchy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, you set self.hierarchy to itself.
import mesa | ||
|
||
|
||
def calculate_shapley_value(self, other_agent): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a function, so don't use self or make it a method on your agent.
Thanks for your PR, and thanks for your patience. I dove in a bit, and I really like meta agents conceptually. Since a meta agent is a collection of agents, I was wondering if it could be an (extended) AgentSet. Having meta-agents extend both Agent and AgentSet would give them all the AgentSet functionality for working with their member agents, while adding meta-agent specific capabilities. Something like: class MetaAgent(AgentSet, Agent):
"""A meta-agent that is both an agent and a collection of agents."""
def __init__(self, model, agents, **attributes):
Agent.__init__(self, model)
AgentSet.__init__(self, agents, random=model.random)
# Add any custom attributes
for name, value in attributes.items():
setattr(self, name, value) This would give meta-agents all the powerful AgentSet functionality for working with their members (select, shuffle, sort, do, map, agg, groupby) while still allowing them to act as agents themselves. Example usage: class Alliance(MetaAgent):
def __init__(self, model, agents, power_threshold=100):
super().__init__(model, agents)
self.total_power = sum(a.power for a in self)
def step(self):
# Use AgentSet methods on members
self.shuffle_do("move")
# Update group properties
self.total_power = self.agg("power", sum)
# Work with subsets of members
elite = self.select(lambda a: a.power > 50) Curious what you think! |
The TLDR of my reaction is: conceptually, this is really interesting and something worth pursuing. Implementation-wise, I have some concerns. Let's start with the implementation side of things first. Ideally, I would like to see the meta agent idea contained within the experimental name space. This makes it easier for me to grasp what is going on. It also gives a lot more leeway to play around with the API. I would suggest moving Conceptually, you have discussed a lot already in #2539. It would, however, be helpful if we could agree on some working definition of what a MetaAgent is. Effectively, a MetaAgent seems to be a group of agents. Agents within this group can show collective behavior. That is, the MetaAgent has state and behavior that is collective on its constituting agents. Moreover, when individuals are approached as members of this group, they might show behavior that they would not show otherwise. That is, individual agents might dynamically acquire access to behaviors when they become a member of a group and are approached as a member of this group. I recently had a discussion with the professor of simulation in my group. He mentioned in passing that there had been an earlier 1970s AMB language that had interesting ideas on agent groups, group forming, collective behavior, and group identity-based individual behavior. I'll follow up with him again because he promised to send me some papers about this. Minor remarkL it seems this pr is not in sync with #2539 because reaction to @ewout
I probably would argue for composition over multiple inheritance in this case, so subclass Agent into MetaAgent and let it have an AgentSet. We might add a few methods to expose the behavior of the underlying agentset were appropriate. However, the |
@EwoutH and @quaquel Thanks for the review! To summarize (let me know if I am misunderstanding anything):
Thanks again! |
Superseded by #2575 |
Summary
This PR is useful for creating meta-agents that represent groups of agents with interdependent characteristics.
New meta-agent classes are created dynamically using the provided name, attributes and functions of sub agents, and unique attributes and functions.
Motive
This exploits Mesa's agent set functionality to allow for more complex models
Implementation
Method has three paths of execution:
Added to Agent.py primarily lines 169 to 230
Added tests in test-agent.py
Usage Examples
I added a basic example of alliance formation using the bilateral shapley value
Step 0- 50 Agents:
Step 8 - 17 Agents of increasing hierarchy added dynamically during code execution:
Additional Notes
Currently restricted to one parent agent and one meta-agent per agent. Goal is to assess usage and expand functionality.