From 4132e4319cfa398f08b4a400399b7b8911030ee4 Mon Sep 17 00:00:00 2001 From: Vaibhav Sharma <88285949+vbv-shm@users.noreply.github.com> Date: Wed, 27 Nov 2024 03:40:26 +0530 Subject: [PATCH] update homophily value in Schelling example --- .codespellignore | 3 +-- benchmarks/configurations.py | 4 ++-- mesa/examples/basic/schelling/agents.py | 1 + mesa/examples/basic/schelling/app.py | 2 +- mesa/examples/basic/schelling/model.py | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.codespellignore b/.codespellignore index 05536e8dbc3..25659aef031 100644 --- a/.codespellignore +++ b/.codespellignore @@ -6,5 +6,4 @@ inactivate ue fpr falsy -assertIn -nD +assertIn \ No newline at end of file diff --git a/benchmarks/configurations.py b/benchmarks/configurations.py index 95bb41c806a..affcbc9302c 100644 --- a/benchmarks/configurations.py +++ b/benchmarks/configurations.py @@ -35,7 +35,7 @@ "parameters": { "height": 40, "width": 40, - "homophily": 3, + "homophily": 0.4, "radius": 1, "density": 0.625, }, @@ -47,7 +47,7 @@ "parameters": { "height": 100, "width": 100, - "homophily": 8, + "homophily": 0.8, "radius": 2, "density": 0.8, }, diff --git a/mesa/examples/basic/schelling/agents.py b/mesa/examples/basic/schelling/agents.py index 326f15493bd..15308321529 100644 --- a/mesa/examples/basic/schelling/agents.py +++ b/mesa/examples/basic/schelling/agents.py @@ -19,6 +19,7 @@ def step(self) -> None: self.pos, moore=True, radius=self.model.radius ) + # Count similar neighbors similar_neighbors = len([n for n in neighbors if n.type == self.type]) diff --git a/mesa/examples/basic/schelling/app.py b/mesa/examples/basic/schelling/app.py index d9811b51b52..4e91ebd8ba0 100644 --- a/mesa/examples/basic/schelling/app.py +++ b/mesa/examples/basic/schelling/app.py @@ -26,7 +26,7 @@ def agent_portrayal(agent): }, "density": Slider("Agent density", 0.8, 0.1, 1.0, 0.1), "minority_pc": Slider("Fraction minority", 0.2, 0.0, 1.0, 0.05), - "homophily": Slider("Homophily", 0.3, 0.0, 0.8, 0.1), + "homophily": Slider("Homophily", 0.4, 0.0, 1, 0.1), "width": 20, "height": 20, } diff --git a/mesa/examples/basic/schelling/model.py b/mesa/examples/basic/schelling/model.py index 3ee0746c073..e9a01cb2116 100644 --- a/mesa/examples/basic/schelling/model.py +++ b/mesa/examples/basic/schelling/model.py @@ -13,7 +13,7 @@ def __init__( width: int = 40, density: float = 0.8, minority_pc: float = 0.5, - homophily: int = 3, + homophily: float = 0.3, radius: int = 1, seed=None, ): @@ -24,7 +24,7 @@ def __init__( height: Height of the grid density: Initial chance for a cell to be populated (0-1) minority_pc: Chance for an agent to be in minority class (0-1) - homophily: Minimum number of similar neighbors needed for happiness + homophily_ratio: Ratio of similar neighbors to total neighbors needed for happiness radius: Search radius for checking neighbor similarity seed: Seed for reproducibility """ @@ -35,7 +35,7 @@ def __init__( self.width = width self.density = density self.minority_pc = minority_pc - self.homophily = homophily + self.homophily_ratio = homophily self.radius = radius # Initialize grid