The ipython notebook is great to interactively play around with some things. Feedback is immediate and directly in front of you.

Once settled on a model / specification, you can just export the code and use it in the "normal" workflow.


In [1]:
# Do not delete this cell. It ensures that you can do the imports,
# load datasets etc. in the same fashion as in any Python script
# in the project template.
import sys
sys.path.insert(0, '../..')
from bld.project_paths import project_paths_join as ppj

In [2]:
import pandas as pd
from matplotlib import pyplot as plt

In [3]:
from src.analysis.schelling import setup_agents

In [4]:
agents = setup_agents({
    'n_types': 2,
    'n_agents_by_type': [20, 10],
    'n_neighbours': 5,
    'require_same_type': 2,
    'max_moves': 50
})

In [5]:
def sim_one_round():
    someone_moved = False
    for agent in agents:
        old_location = agent.location
        # If necessary, move around until happy
        agent.move_until_happy(agents)
        if not (agent.location == old_location).all():
            someone_moved = True
    return someone_moved

In [6]:
locs_0 = pd.DataFrame(
    [a.location for a in agents if a.type == 0],
    columns=['x', 'y']
)
locs_1 = pd.DataFrame(
    [a.location for a in agents if a.type == 1],
    columns=['x', 'y']
)
ax = locs_0.plot(x='x', y='y', kind='scatter')
ax.plot(locs_1['x'], locs_1['y'], "o", markerfacecolor="orange")


Out[6]:
[<matplotlib.lines.Line2D at 0x7f5620d63450>]

In [7]:
sim_one_round()


Out[7]:
True

In [ ]: