Skip to content

MaxwellRebo/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.


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

First setup your virtual environment and install the requirements.

Note that pandas 18.0 (not yet released) is required to fix the following bug: pandas-dev/pandas#11699.

You can run the simulation on a single machine like so:

python run.py <population size> <number of days>

Running a simulation with a lot of agents is slow, so this simulator supports running the simulation across multiple machines.

Start up the arbiter node (the node that manages workers) like so:

cess arbiter <host:port>

Then on each worker machine, start workers like so:

cess node <arbiter host:port>

This creates a worker process for each core on the machine.

Then, run the simulation across the cluster:

python run.py <population size> <number of days> <arbiter host:port>

Running the frontend

(run each of the following in separate tabs)

# run redis
redis-server

# run the server
python app

# 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

Sources

About

humans of simulated new york

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 59.9%
  • JavaScript 18.3%
  • CSS 12.8%
  • HTML 8.8%
  • Shell 0.2%