Comments (42)
Now really full solution of this, but some thoughts:
- In it's simplest form, a neighborhood definition can just be a dictionary:
neighborhood_def = {include_center: False, radius: 1, moore: True}
- It could also be a simple object.
class NeighborhoodDefinition:
def __init__(self, include_center=False, radius=1, moore=True):
self.include_center = include_center
self.radius = radius
self.moore = moore
- A dataclass could make this more elegant
- However, we have to consider different grid types (like hex and network) that take different keywords
- Each grid could have a
get_neighborhood_definition()
method that gives a definition that can be used in all methods of that grid type (whether it's a dict, object or something else).
from mesa.
An advantage of using a simple dictionary would be to directly use the definition via unpacking. So Imho we could do
grid.get_neighbirhood(pos, **neighborhood_def)
Whenever we need the values in a traditional function.
Or do you suggest changing the API to get_neighborhood(pos, neighborhood_def)
?
from mesa.
But this issue has let me to think about how we define theesa space API and if we should switch to a more "chainable" API?
So for example instead of doing grid.get_neighbors(pos, moore, radius, center)
We do something like this
grid[pos] # get the current position (a Position)
.neighborhood(moore, radius, center) # get the neighborhood (a PositionList)
.agents # get the agents (an AgentList)
So we would have all those intermediate classes with their own attributes and methods.
In this case it might seem a bit verbose, but I think especially combined with properties we can have a much cleaner and more powerful way of extracting the things we want. I mean to say that we can have simpler functions as building blocks for complex logic and not having highly specialized functions like move_agent_to_extreme_value_cell
.
What do you think?
from mesa.
Thanks for the insights!
I like both ideas of the dictionary unpacking and the chainable API (feels a bit like Pandas). I don't know yet which I prefer.
It might be useful to discuss this at the dev meeting.
from mesa.
Related Issues (20)
- JupyterViz: after changing parameters, play button does not work HOT 2
- JupyterViz: allow customizing the controls/display for a single model, e.g. to display status (running/converged) HOT 1
- Clean up HexSingleGrid(HexGrid) andHexGrid HOT 3
- phoneinfoga error: could not open requirements file: [errno 21] is a directory: 'requirements.txt' HOT 2
- JupyterViz / Solara visualisation doesn't work in JetBrains PyCharm/DataSpell Jupyter notebooks HOT 5
- mesa.visualization.chartmodule doesn't work HOT 6
- jupyterviz agent space and measures flash on mesa 2.1.4 HOT 2
- TyperError when model reporter is a partial function
- Proposal: Adding Cell Properties to Grids in Mesa HOT 22
- Latest Mesa build is failing on conda-forge HOT 7
- Enable DiscreteEventScheduler to handle system-level events and task interruptions
- Add Voronoi tessellation space
- Add Triangle mesh space
- Proposal: Flexible move_agent method that allows multiple movement strategies HOT 5
- Proposal: Agent selection method HOT 7
- JupyterViz: disabled space drawer is ignored when rendering in the browser HOT 1
- jupyterviz: best practices for model layout HOT 1
- best practices / example for parameter sweep with batch runner HOT 15
- AttributeError: 'Model' object has no attribute 'agents' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mesa.