Binary Voter Model
A simulation to reproduce the original Binary Voter Model of Clifford and Sudbury 1973[1] and Holley and Liggett 1975[2].
Main.bvm.run_sim
— Functionfunction run_sim(n::Integer=20, p::Float64=0.2,
influencer::Bool=false, replacement::Bool=false;
verbose::Bool=true, make_plots::Bool=true, make_anim::Bool=false)
Run a single simulation of the Binary Voter Model on a randomly-generated graph. Continue until convergence (uniformity of opinion) is reached.
Arguments
n
,p
: Parameters to the Erdos-Renyi random graph model (n
= number of nodes,p
= probability of each pair of nodes being adjacent.)influencer
iftrue
, makes the randomly selected node change the opinion of its randomly selected neighbor. Iffalse
, makes its randomly selected neighbor change the opinion of the randomly selected nodereplacement
: iftrue
, puts back the last randomly selected node in the list of next nodes that can be selected. Iffalse
, takes out the last randomly selected node from the list of next nodes that can be selected.verbose
: iftrue
, print output showing progress of simulation.make_plots
: iftrue
, saves a time series plot of the simulation.make_anim
: iftrue
, saves an animated gif of the simulation.
Returns
a tuple of values:
- a status message (String)
- a DataFrame of results with columns:
:iter
: Iteration number:frac_red
: The fraction of nodes that had the Red opinion
Main.bvm.param_sweep
— Functionfunction param_sweep(num_trials=10, this_n=20, this_p=0.2,
influencer=false, replacement=false)
Run two entire parameter sweeps of simulations, one for varying values of n
(number of nodes in random graph) and the other for varying values of p
(edge probability). Plot output will be created in the files n_list_plot.svg
and p_list_plot.svg
.
Arguments
num_trials
: the number of trials for each fixed combination of parameters.make_anim
: iftrue
, saves an animated gif of the simulation.this_n
: value ofn
that will be constant asp
is iterated.this_p
: value ofp
that will be constant asn
is iterated.influencer
,replacement
: passed torun_sim()
(see notes there).
Returns
- nothing
Main.bvm.conf_int_sweep
— Functionfunction conf_int_sweep(num_trials=10, n=20, influencer=false,
replacement=false)
Run a suite of simulations for varying values of p
(probability of edge in random graph), and plot λ ($=N×p$) vs. num-iterations-to-converge with a 95% confidence band. The plot will be stored in sweep
n.svg
.
Arguments
num_trials
: the number of trials for each value ofp
(and λ).n
: the number of nodes in the random graph.influencer
,replacement
: passed torun_sim()
(see notes there).
Returns
- nothing
References
- 1Clifford, P., & Sudbury, A. (1973). A Model for Spatial Conflict. Biometrika, 60(3), 581–588. https://doi.org/10.2307/2335008
- 2Holley, R. A., & Liggett, T. M. (1975). Ergodic theorems for weakly interacting infinite systems and the voter model. The Annals of Probability, 643–663. http://dx.doi.org/10.1214/aop/1176996306