Skip to content
/ hosny Public
forked from frnsys/hosny

humans of simulated new york

Notifications You must be signed in to change notification settings

spamwell/hosny

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Humans of Simulated New York

This is an (in-progress) New York City simulator.

Using Census and other data (see below for references), a population of plausible simulated New Yorkers are generated and distributed through the simulated city. They live their lives day to day, trying their best, as the world around them changes according to historical data points (unemployment rates, market data, etc) from 2005 to 2014.

A static demo can be explored here: Public Science Agency


You can generate a simulated New Yorker like so:

from people import generate
year = 2005
person = generate(year)
print(person)

{
    'age': 36,
    'education': <Education.grade_12: 6>,
    'employed': <Employed.non_labor: 3>,
    'wage_income': 3236,
    'wage_income_bracket': '(1000, 5000]',
    'industry': 'Independent artists, performing arts, spectator sports, and related industrie
    s',
    'industry_code': 8560,
    'neighborhood': 'Greenwich Village',
    'occupation': 'Designer',
    'occupation_code': 2630,
    'puma': 3810,
    'race': <Race.white: 1>,
    'rent': 1155.6864868468731,
    'sex': <Sex.female: 2>,
    'year': 2005
}

Technical details

Individual-level New Yorker data (see the IPUMS resources below) is used to learn a Bayes Net that then is sampled to generate simulated New Yorkers. Thus the generated New Yorkers are "plausible" in that correlations that exist in the real world are reflected in them.

Each New Yorker is designed as an (expected) utility-maximizing agent. They are configured with some utility functions (determining how much, for example, stress bothers them, and how happy money makes them), some possible actions (such as working or sleeping), and goals (such as paying the rent). Overtime, they may make new goals as well. Each day they make a plan for that day (for speed, this is a simple hill-climbing search algorithm) and try to their best to accomplish it.

Simulated New Yorkers also have their own social networks - based on the model used in this study, two simulated New Yorkers may become friends by some chance, depending on their similarity. This affects things like their ability to find employment.

As days go by, the world environment changes according to real historical data; this can have an effect on the simulated New Yorkers. For instance, when unemployment rates are up, they have a higher chance of losing their job (depending on factors such as their race and sex; these correlations are also derived from real data).

Usage

Setup

First setup your virtual environment and install the requirements:

pip install -r requirements.txt

We also need cess:

git clone https://github.com/frnsys/cess.git
cd cess
pip install --editable .

And handlebars:

npm install -g handlebars

Then compile the JS templates:

cd app/static/js
bash compile

Running

(run each of the following in separate tabs)

# run redis
redis-server

# run the server
python app.py

# run the celery worker
# only run one celery process; this is a bit of a hack to ensure that
# only one City model is created and we step only that model
celery -A app.tasks.celery worker --concurrency=1

Then visit http://localhost:5000.

You'll be presented with a screen which provides some basic world configuration options. Hit "Let's Start" and you'll be taken to the main simulation screen. Hit "Start Month" to run one month of the simulation.

Data

Running the simulation will generate a log file at simulation.log. You can run the provided log_to_csv.py script to process this into a CSV of the simulation data.

Sources

About

humans of simulated new york

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 60.0%
  • JavaScript 18.3%
  • CSS 12.7%
  • HTML 8.8%
  • Shell 0.2%