Code Monkey home page Code Monkey logo

hosny's Introduction

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

hosny's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.