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 [ ]:
# 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.
%matplotlib inline
import sys
sys.path.insert(0, '../..')
from bld.project_paths import project_paths_join as ppj
In [ ]:
import pandas as pd
from matplotlib import pyplot as plt
In [ ]:
from src.analysis.schelling import setup_agents
In [ ]:
agents = setup_agents({
'n_types': 2,
'n_agents_by_type': [20, 10],
'n_neighbours': 5,
'require_same_type': 2,
'max_moves': 50
})
In [ ]:
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 [ ]:
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")
In [ ]:
sim_one_round()
In [ ]:
In [ ]: