Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, November 13, 2023

Synthetic Geosocial Network Generation

In the past the blog has explored the creation of social networks for models. Keeping with this vain of research, I was fortunate to work with Ketevan Gallagher, Taylor Anderson and Andreas Züfle to consider the role of location of individuals when generating social networks. This work has resulted in a new paper entitled "Synthetic Geosocial Network Data Generation"  which was presented at the 7th ACM SIGSPATIAL Workshop on Location-based Recommendations, Geosocial Networks and Geoadvertising (LocalRec 2023). If this sounds of interest, below you can read the abstract to the paper, see some the generated geosoical networks and find the full reference and link to the paper. In addition to this, the Python code and data used to generate the networks is available at https://github.com/KetevanGallagher/Synthetic-Geosocial-Networks.

Abstract: Generating synthetic social networks is an important task for many problems that study humans, their behavior, and their interactions. Geosocial networks enrich social networks with location information. Commonly used models to generate synthetic social networks include the classical Erdos-Renyi, Barabasi-Albert, and Watts-Strogatz models. However, these classic social network models do not consider the location of individuals. Real-world geosocial networks do exhibit a strong spatial autocorrelation, thus having a higher likelihood of a social connection between agents that are spatially close. As such, recent variants of the three classical models have been proposed to consider location information. Yet, these existing solutions assume that individuals are located on a uniform lattice and exhibit certain limitations when applied to real-world data that exhibits clusters. In this work, we discuss these limitations and propose new approaches to extend the three classic social network generation models to geosocial networks. Our experiments show that our generated synthetic geosocial networks address the shortcomings of the state-of-the-art models and generate realistic geosocial networks that exhibit high similarity to real-world geosocial networks. 
Keywords: Geosocial Networks, Network Generation, Synthetic Social Networks, Erdos-Renyi, Watts-Strogatz, Barabasi-Albert.


Real- World Geosocial Network using Facebook Social Connectedness Data between Zone Improvement Plan (ZIP) Region Centroids for the State of Virginia, USA.
Geosocial graphs using Virginia ZIP code data.
Graphs using Fairfax Census Tract data.


Full Referece:
Gallagher, K., Anderson, T., Crooks, A.T. and Züfle, A. (2023), Synthetic Geosocial Network Data Generation, Proceedings of the 7th ACM SIGSPATIAL Workshop on Location-based Recommendations, Geosocial Networks and Geoadvertising (LocalRec 2023), Hamburg, Germany. (pdf) (presentation)

Friday, November 03, 2023

Geographically Synthetic Populations for ABM: A Gallery of Applications

Often we are building geographically explicit agent-based models we spend a lot of time creating the synthetic population to instantiate our artificial world. We have tired to overcome this with creating methods to generate such populations (see this old blog post). Building on this work, Na (Richard) Jiang, Fuzhen Yin, Boyu Wang and myself have a new paper entitled "Geographically-Explicit Synthetic Populations for Agent-based Models: A Gallery of Applications" which was presented at 2023 Computational Social Science Society of the Americas conference. In the paper we extend the synthetic population to the whole of New York state. While at the same time we introduce a pipeline for using the population datasets for model initialization. To show this pipeline, we present several case studies utilizing Python and Mesa. These models range from that of commuting to disease spread and vaccination uptake. If this sounds of interest, below we provide the abstract to the paper along with some of the key figures including our pipeline and example applications. At the bottom of the page we provide the full reference and a link to the paper which has links to the models and data.
Abstract: Over the last two decades, there has been a growth in the applications of geographically-explicit agent-based models. One thing such models have in common is the creation of synthetic populations to initialize the artificial worlds in which the agents inhabit. One challenge such models face is that it is often difficult to create reusable geographically-explicit synthetic populations with social networks. In this paper, we introduce a Python based method that generates a reusable geographically-explicit synthetic population dataset along with its social networks. In addition, we present a pipeline for using the population datasets for model initialization. With this pipeline, multiple spatial and temporal scales of geographically-explicit agent-based models are presented focusing on Western New York. Such models not only demonstrate the utility of our synthetic population on commuting patterns but also how social networks can impact the simulation of disease spread and vaccination uptake. By doing so, this pipeline could benefit any modeler wishing to reuse synthetic populations with realistic geographic locations and social networks. 
Keywords: Agent-Based Model, Geographically-Explicit Agent-Based Models, Synthetic Population, Python, Mesa.
Pipeline of Utilizing Synthetic Population Resulting Datasets in Agent-Based Models.

Large Scale Disease Spread Model Structure.

Disease Dynamics for Two Diseases.

Vaccination Opinion Dynamic Model.

Simulation Vaccination Rate v.s. Real Vaccination Records: (A) All Population; (B) Different Age Groups of Population.

Full Referece: 

Jiang, N., Crooks, A.T., Yin, F. and Wang B. (2023), Geographically-Explicit Synthetic Populations for Agent-based Models: A Gallery of Applications, Proceedings of the 2023 Conference of The Computational Social Science Society of the Americas, Santa Fe, NM. (pdf)

Thursday, September 07, 2023

Agent-Based Modeling of Consumer Choice

At the upcoming International Conference on Geographic Information Science (GIScience 2023) Boyu Wang and myself have a new paper entitled "Agent-Based Modeling of Consumer Choice by Utilizing Crowdsourced Data and Deep Learning." In the paper we explore how through mining Yelp reviews can inform an agents choices of restaurants. The model itself was created in Mesa and uses Mesa-Geo and  more details about the model can be found at https://github.com/wang-boyu/yelp-abm.  If this sounds of interest, below you can see the abstract to the paper, some fugues including the graphical user interface of the model and a link to the paper.

Abstract: People’s opinions are one of the defining factors that turn spaces into meaningful places. Online platforms such as Yelp allow users to publish their reviews on businesses. To understand reviewers' opinion formation processes and the emergent patterns of published opinions, we utilize natural language processing (NLP) techniques especially that of aspect-based sentiment analysis methods (a deep learning approach) on a geographically explicit Yelp dataset to extract and categorize reviewers' opinion aspects on places within urban areas. Such data is then used as a basis to inform an agent-based model, where consumers' (i.e., agents') choices are based on their characteristics and preferences. The results show the emergent patterns of reviewers' opinions and the influence of these opinions on others. As such this work demonstrates how using deep learning techniques on geospatial data can help advance our understanding of place and cities more generally.


Keywords: aspect-category sentiment analysis, consumer choice, agent-based modeling, online restaurant reviews.

An overview of proposed agent-based model logic.

Average star rating vs. average sentiment by aspect category for 200 randomly selected restaurants in the City of St. Louis, MO.

The prototype agent-based model (a) with simulated (b) and actual visiting patterns (c).

Full reference:

Wang, B. and Crooks, A.T. (2023), Agent-Based Modeling of Consumer Choice by Utilizing Crowdsourced Data and Deep Learning, in Beecham, R., Long, J.A., Smith, D., Zhao, Q., and Wise, S (eds), Proceedings of the 12th International Conference on Geographic Information Science (GIScience 2023), Dagstuhl Publishing, Dagstuhl, Germany., pp. 81:1-81:6. (pdf)


Thursday, January 26, 2023

Repast4Py

In the past we have blogged about how we are using the Python agent-based modeling framework Mesa. But we would be remiss if we did not also mention other Python toolkits. One of which is Repast4Py from the people we created Repast suite. To quote from their user guide website:

To find out more about Repast4Py I highly recommend readers to look at the following publications or their webpage: https://repast.github.io/repast4py.site/.

References:

 

Tuesday, November 01, 2022

Mesa-Geo: ABM and GIS in Python (A Update)

A couple of months ago we had a post about Mesa-Geo but only a short one. Now we want to go into more detail as we (Boyu Wang, Vincent Hess and myself) just presented a paper about it at the 5th ACM SIGSPATIAL International Workshop on Geospatial Simulation (GeoSim 2022). The paper itself was entitled "Mesa-Geo: A GIS Extension for the Mesa Agent-Based Modeling Framework in Python" in which we discuss in detail the need for a python library for creating geographically explicit agents (or GeoAgents) and introduce its architecture. 

In the paper we detail how we have designed Mesa-Geo to handle spatial data (both in terms of raster and vector via GeoSpace), how we have enabled visualization of geographical data and such models along with creating features to export geographical data from the simulations (using Rasterio and GeoPandas). To support this discussion we also provide some explicit examples on how the pieces fit together  range from rainfall flowing over a digital terrain model (DEM) to Schelling types of models using points and polygons as agents, to that of agents using road networks to navigate over an area. Boyu has also put together more details about the examples at: https://mesa-geo.readthedocs.io/en/latest/examples/overview.html (which includes movies of them running).  The actual code for the models and Mesa-Geo can be found at https://github.com/projectmesa/mesa-geo. Just to give you a sense of the paper and what Mesa-Geo can do, below we provide the abstract to the paper, some figures showing the architecture, along with some example applications. While at the bottom of the post you can see the full reference and a link to the paper itself.  

 

Abstract: Mesa is an open-source agent-based modeling (ABM) framework implemented in the Python programming language, allowing users to build and visualize agent-based models. It has been used in a diverse range of application areas over the years ranging from biology to workforce dynamics. However, there has been no direct support for integrating geographical data from geographical information systems (GIS) into models created with Mesa. Users have had to rely on their own implementations to meet such needs. In this paper we present Mesa-Geo, a GIS extension for Mesa, which allows users to import, manipulate, visualize and export geographical data for ABM. We introduce the main components and functionalities of Mesa-Geo, followed by example applications utilizing geographical data which demonstrates Mesa-Geo's core functionalities and features common to agent-based models. Finally, we conclude with a discussion and outlook on future directions for Mesa-Geo.

Class diagram of the Agent, GeoAgent, and Cell classes
Component diagram of GeoSpace and its related classes
Example applications using Mesa and Mesa-Geo: (a) Rainfall model, (b) Population model, (c) GeoSchelling (polygons) model, (d) GeoSchelling (points \& polygons) model, and (e) Agents and networks model.


 If you have any thoughts or comments about Mesa-Geo please let us know.

Full reference:

Wang, B., Hess, V. and Crooks A.T. (2022), Mesa-Geo: A GIS Extension for the Mesa Agent-Based Modeling Framework in Python, Proceedings of the 5th ACM SIGSPATIAL International Workshop on Geospatial Simulation (GeoSim 2022), Seattle, WA. pp 1-10. (PDF)

Thursday, February 17, 2022

New Paper: Synthetic Populations with Social Networks

When developing geographically explicit agent-based models, one thing we spend a lot of time on is building synthetic populations and then linking the agents in the synthetic population to each other.  To overcome this issue we have a new paper published in "Computational Urban Science " entitled "A method to create a synthetic population with social networks for geographically-explicit agent-based models" In this paper  Na (Richard) Jiang, Hamdi Kavak, Annetta Burger, William Kennedy and myself present a synthetic population generation method that also includes social networks and use the New York Metro as a study site, which covers an area of 262 x 234 km and is home to over 23 million people. 

To show the utility of this method we also present three simple applications (e.g., a disease , a disaster  and a traffic model) which utilize different parts of this synthetic population but are all geographically explicit and use networks in some shape or form. If this sounds of interest, below you can read the abstract from the paper, along with seeing some of the figures from our methodology and example applications. While at the bottom of the post we provide the full citation and a link to the paper. The paper itself also has links to actual code that generates the synthetic population and the resulting datasets and models  (code: https://bit.ly/SynPopABM; source and resulting synthetic population data: https://osf.io/3vsaj/) .  

Abstract: 

Geographically-explicit simulations have become crucial in understanding cities and are playing an important role in urban science. One such approach is that of agent-based modeling which allows us to explore how agents interact with the environment and each other (e.g., social networks), and how through such interactions aggregate patterns emerge (e.g., disease outbreaks, traffic jams). While the use of agent-based modeling has grown, one challenge remains, that of creating realistic, geographically-explicit, synthetic populations which incorporate social networks. To address this challenge, this paper presents a novel method to create a synthetic population which incorporates social networks using the New York Metro Area as a test area. To demonstrate the generalizability of our synthetic population method and data to initialize models, three different types of agent-based models are introduced to explore a variety of urban problems: traffic, disaster response, and the spread of disease. These use cases not only demonstrate how our geographically-explicit synthetic population can be easily utilized for initializing agent populations which can explore a variety of urban problems, but also show how social networks can be integrated into such populations and large-scale simulations.

Keywords: Synthetic Population Generation, Agent-Based Modeling, New York, Traffic Dynamics, Disease, Disaster

Study Area

Workflow for Generation of Synthetic Population and Networks

Creation of Social Networks: (a) Selected Population; (b) Creation of a Household Network; (c) Creation of Work and Educational Networks for each Member of the Household; (d) The Household, its Networks within the Full Census Tract

Model Component Structure of Population Respond to Disaster event

Agents’ Health Status After 1 Minute of the Disaster Event

Full Reference:

Jiang, N., Crooks, A.T., Kavak, H., Burger, A. and Kennedy, W.G. (2022), A Method to Create a Synthetic Population with Social Networks for Geographically Explicit Agent-Based Models, Computational Urban Science, 2:7. Available at https://doi.org/10.1007/s43762-022-00034-1

Thursday, October 15, 2020

Utilizing Python for Agent-based Modeling: The Mesa Framework

In the past I have mentioned Mesa, an agent-based modeling framework in Python is several posts but not really discussed it in detail. This is about to change with this post. The reason being is that we have a paper at the forthcoming International Conference on Social Computing, Behavioral-Cultural Modeling and Prediction and Behavior Representation in Modeling and Simulation (or SBP-BRiMS for short) entitled "Utilizing Python for Agent-based Modeling: The Mesa Framework".

While Mesa started off with two students from the CSS program at George Mason University: Jackie Kazil and David Masad it has now grown to include over 70 contributors. In this new paper we discuss the rationale for developing Mesa (see https://github.com/projectmesa/mesa) which arose because there was no framework for easily building agent-based models in Python. Furthermore we discuss Mesa's design goals and its architecture and usage, along with who is using Mesa and extensions to it (e.g. Mesa-Geo, Multi-Level Mesa), finally we conclude the paper with future development directions. Below we provide the abstract to the paper and a selection of figures which highlights Mesa's model components (model, analysis and visualization), how various activation schedules are incorporated within Mesa and an illustration of how these different schemes impact a model and some examples of Mesa's visualization functionality. At the bottom of the post we have the full reference and a link to the paper.

Abstract.
Mesa is an agent-based modeling framework written in Python. Originally started in 2013, it was created to be the go-to tool in for re-searchers wishing to build agent-based models with Python. Within this paper we present Mesa’s design goals, along with its underlying architecture. This includes its core components: 1) the model (Model, Agent, Schedule, and Space), 2) analysis (Data Collector and Batch Runner) and the visualization (Visualization Server and Visualization Browser Page). We then discuss how agent-based models can be created in Mesa. This is followed by a discussion of applications and extensions by other researchers to demonstrate how Mesa design is decoupled and extensible and thus creating the opportunity for a larger decentralized ecosystem of packages that people can share and reuse for their own needs. Finally, the paper concludes with a summary and discussion of future development areas for Mesa. 

Keywords: Agent-based Modeling, Python, Framework, Complex Systems. 
Mesa model components: model, analysis and visualization.
Activation schedules within Mesa and an illustration of how these different schemes impact a model. In this case the Prisoner’s Dilemma. Defecting agents are in red and cooperating agents are in blue. Each image is from the same step, but different activation schemes are used.
Model visualization of two Mesa applications within a web browser: (A) Wolf-sheep predation Model. (B) Virus on a network (Source: https://github.com/projectmesa).

Full Reference: 
Kazil, J., Masad, D. and Crooks, A.T. (2020), Utilizing Python for Agent-based Modeling: The Mesa Framework, in Thomson, R., Bisgin, H., Dancy, C., Hyder, A. and Hussain, M. (eds), 2020 International Conference on Social Computing, Behavioral-Cultural Modeling & Prediction and Behavior Representation in Modeling and Simulation, Washington DC., pp. 308-317. (pdf)

Thursday, April 30, 2020

Exploring the Effects of Link Recommendations on Social Networks


Most people today are actively engaged on at least one social networking site, enabling individuals to keep in touch with old friends, connect with new people, and rapidly disseminate information to all. The method by which users find and link up with others online is often assisted by recommendation systems. A common technique utilized by online social networking sites (e.g., LinkedIn, Facebook) is to make link recommendations based upon friends of friends, or shared mutual connections. This method exploits a user’s social network structure, and specifically transitivity, to predict that a user will be interested in connecting with an individual who is also connected with that user’s friends, (i.e., “I am more likely to like someone who several of my friends like, than someone chosen at random”).

Despite the wide use of recommendation algorithms, little is known about the way in which recommendation systems impact the structure of online social networks. To address this problem at the upcoming (now virtual) 2020 Spring Simulation Conference we have a paper entitled "Exploring the Effects of Link Recommendations on Social Networks: An Agent-Based Modeling Approach."

This paper contributes to this limited area of (publicly available) research by demonstrating how a stylized agent-based model can be used to explore societal, network-level effects of commonly used online link recommendations from the bottom up. Below we provide the abstract to the paper, the steps the model takes to generate the online social network, the types of metrics outputted by the model and a selection of some of the results. While at the bottom of the post we provide the full reference to the paper. Further details about the model, in the Overview, Design Concepts, and Details (ODD) format along with the Python source code can be found at https://www.comses.net/codebase-release/3203a44a-fcb0-4957-a3b7-8323f829c0c4/. 

Abstract:
The vast majority of recommender system research has focused on improving performance accuracy, while limited work has explored their societal, network level effects. This paper demonstrates how simulation can be used to investigate macro level effects of online social network link recommendations, such as whether these technologies may be fragmenting or bridging communities of individuals. An agent-based model is presented that generates stylized online social networks with different percentages of real world contacts and link recommendations. Results show that networks with higher percentages of recommendation-based links produce more clustered, distinct, and dispersed communities, suggesting that these technologies could fragment society. Furthermore, scale-free network properties diminished with higher percentages of recommendations, suggesting that these technologies could be contributing to recent findings that social networks are at most ‘weakly’ scale-free. Building upon this research, further simulation work could inform the design of link recommendation algorithms that help connect both individuals and communities.

Keywords: online social network, social network analysis, mutual connection link recommendation system, friend-of-friend recommender, agent-based modeling.
Online network generation process
Social Network Analysis definitions for metrics output by this model
The effect of link recommendations on mean clustering coefficient and modularity. Error bars represent one standard deviation.
Probability density functions showing the degree distribution of Online networks (beginning top left and increasing left to right, top to bottom) with link recommendation percentage levels: 0, 10, 20, 30, 40, and 50. The blue line represents the empirical data, and red and green dotted lines represent fit lines corresponding with the power-law and lognormal distributions, respectively.

Full Reference: 
Sibley, C. and Crooks, A.T. (2020), Exploring the Effects of Link Recommendations on Social Networks: An Agent-Based Modeling Approach, Spring Simulation Conference (SpringSim’20), Fairfax, VA. (pdf)

Update: Our paper was selected as runner-up for best paper.

Friday, September 25, 2015

Mesa: An Agent-Based Modeling Framework in Python

Just a short post to say two of our PhD students, David Masad and Jackie Kazil have been developing an agent-based modeling framework in Python called Mesa.

To quote from David's talk abstract:
"Agent-based modeling is currently a hole in in Python’s robust and growing scientific ecosystem. Mesa is a new open-source package meant to fill that gap. It allows users to quickly create agent-based models using built-in core components (such as agent schedulers and spatial grids) or customized implementations; visualize them using an innovative browser-based interface; and analyze their results using Python’s robust data analysis tools. Its goal is to be a Python 3-based alternative to other popular frameworks based in other languages such as NetLogo, Repast, or MASON."

Below is short presentation outlining Mesa from SciPy 2015:


Tuesday, May 26, 2015

A Semester with Spatial Agent-based Models

With the spring semester over, I thought I would show some of the final agent-based modeling projects that were carried out in CSS 645: Spatial Agent-based Models of Human-Environment Interactions. As always I was quite impressed the models and we had a plethora of topics ranging from mobile agent-based models, shopping, pick pocketing, route finding, travel to work, the spatial spread of information, deer management, urban growth etc... What is interesting is that while the majority of models are implemented in NetLogo, more and more are being done in Python.


Something new for this semester is we also tried to reproduce a published model. Below you can see 3 examples of such work. Click here to see a previous post on reproduction and replication.