DATA 420 - Modeling and Simulation - Spring 2026

Homeworks #5 & #6 — Agent-Based Models II

Possible experience: +80XP

Due: Thursday, April 16, midnight

The Binary Voter Model

In this project, you'll be making two modifications to the Binary Voter Model and investigating how those changes to agent behavior affect the simulation's outcome (including its convergence time).

The two sets of changes you will make sorta correspond to "homework #5" and "homework #6." The two changes, and the analysis of their behavior, can be done in either order. But I do want them turned in together, as one combined assignment submission.

Instructions

Preparation

Use the implementation we wrote in class as a starting point for this assignment. Make sure you can get it running in your environment, and that you can see both the animation and the time plot of average blueness at the end.

Change α: certainty

  1. Give each agent a certainty instance variable, which will be an integer ranging from 0 to some maximum "certainty ceiling" value. (You can use 10 as an initial value for the ceiling.) An agent's certainty represents how committed that agent is to its current opinion (color). Each agent, when its constructor runs, should set its certainty to a value uniformly randomly in the range from 0 to certainty_ceiling.

    When an agent runs its .step() method, and chooses a neighbor at random, here's what it should do instead of blindly copying the neighbor's color (as it does now): Also, you should display the agent's node in the animation with a size proportional to its certainty. You can use the node_size parameter to the nx.draw_networkx_nodes() function to accomplish this, just like we did for the node_color parameter. Try these values: for each agent, a certainty of 0 should produce a node_size of 100, and a certainty of the maximum (i.e. at the certainty ceiling) should give a node_size of 1000, with the intermediate values being linear in that range. (If you're confused as to how to convert a certainty value to a node size, remember your y=mx+b from high school which will come in handy. If you're still confused after thinking about that, send me email or come see me in office hours.)
  2. Once you've got it working, play with the sim's parameters, including the certainty ceiling, and try to grok the effect of these changes. Write down a couple observations about what you see.
  3. Now turn off the plotting (with if statements) and run a parameter sweep, where the independent variable is the certainty ceiling, and the dependent variable is the mean time to convergence. You'll need to let the seed vary, of course, instead of fixing it like we did in the original surgery.py. Be sure to run enough simulations in each suite that randomness is evened out.

Change β: rewiring

  1. Give agents the ability to change the graph. Each time an agent chooses a neighbor of a different color, they will choose one of the following homophilous behaviors: (a) convert to that neighbor's color, or (b) terminate their relationship with that neighbor and replace it with a new relationship.
  2. More formally, with probability convert_prob, they will adopt the neighbor's color, as before; but with probability 1-convert_prob, they will instead be pissed off at the neighbor and sever their connection (remove the edge between them). To appease Marina and help save the environment, I'll save everyone an AI query by pointing you to the .remove_connection() Network method.

    Now in order to maintain the node's degree (and to avoid the complete social isolation that will occur if friendships start terminating with no replacements), when this happens the agent must also form a new friendship. This is accomplished by adding an edge to the graph. To do this, it will choose one of its FOAFs (friends-of-a-friend) at random, and if it doesn't already have an edge with that FOAF, it will add one. (If you wish, you can make this operation "smarter" by having the agent choose a FOAF whose color agrees with them, if one is available, but if you'd rather just choose randomly among FOAFs that's okay too.)
  3. Once you've got it working, play with the sim's parameters, including the convert_prob, and try to grok the effect of these changes. Write down a couple observations about what you see.
  4. Now turn off the plotting (with if statements) and run a parameter sweep, where the independent variable is the conversion probability, and the dependent variable is the mean time to convergence. You'll need to let the seed vary, of course, instead of fixing it like we did in the original surgery.py. Be sure to run enough simulations in each suite that randomness is evened out.

Turning it in

Send me an email with four attachments: (1) a .py file with your modified BVM simulation that includes both changes (certainty and rewiring); (2) the two .png files depicting your parameter sweep results; and (3) a brief report (using plain-text or any word processor) with your observations about the effect of each change, and your overall takeaways from this assignment. The subject line of this email should be "DATA 420 Homeworks #5 & #6 turnin".

Getting help

Come to office hours, or send me email with subject line "DATA 420 Homeworks #5 & #6 help!!"