Social Learning

The Voter Model

This model of social learning was independently introduced in Clifford and Sudbury (1973), Holley and Liggett (1975). The setting and dynamic process are the following:

  • Each agent has its own opinion
  • On each iteration an agent chooses its neighbour and adopts its side

It was shown that agents' states reach a consensus over any connected graph $G$ (Coalescing Random Walks).


In [ ]:
import numpy as np
import scipy as sp

import networkx as nx

import matplotlib.pyplot as plt

from numpy.linalg import eig
from scipy.integrate import odeint

%matplotlib inline

Task 1

Implement the Voter Model and check how the number of agents' states changes with time. Run it for Karate club and Political Blogs networks.


In [ ]:
G = nx.karate_club_graph()
# Continue your code here
#..
opinions = np.random.uniform( size = G.number_of_nodes( ) )

In [ ]:
opinions = np.random.uniform( size = G.number_of_nodes( ) )

In [ ]:
def voter( G, O, niter = 10000 ) :
    tick = np.full( G.number_of_nodes(), np.inf, np.float )
    kiter = 0.0
    while kiter < niter :
## pick a random node
        v = np.random.choice( G.nodes( ) )
## pick a random neighbour
        w = np.random.choice( G[ v ].keys( ), size = 1 )
        if O[ v ] != O[ w ] :
            O[ v ] = O[ w ]
            if not np.isfinite( tick[ v ] ) :
                tick[ v ] = kiter
        kiter += 1
    return O, tick

In [ ]:
voter( G, opinions )

In [ ]:
# Some preprocessing for polblogs
A = nx.adj_matrix(nx.read_gml('./data/polblogs.gml'))
G = nx.Graph( A )
for n, d in G.degree_iter( ):
    if d == 0: 
        G.remove_node( n )

mapping = { }
i = 0
for n in G.nodes_iter():
    mapping[ n ] = i
    i += 1
G = nx.relabel_nodes( G, mapping )

Task 2*

Try to write a code that identifies the path of opinion adoption starting from a particular node


In [ ]:
# Continue your code here
#..
def voter( G, opinions ) :
    kiter = 0.0
    while kiter < niter :
## pick a random node
        v = np.random.choice( G.nodes( ) )
## pick a random neighbour
        w = np.random.choice( G[ v ].keys( ), size = 1 )
        if O[ v ] != O[ w ] :
            O[ v ] = O[ w ]
            if not np.isfinite( tick[ v ] ) :
                tick[ v ] = kiter
        kiter += 1

References

  1. Clifford, P., and A. Sudbury, "A model for spatial conflict", 1973.
  2. Holley R and Liggett T M, "Ergodic Theorems for Weakly Interacting Infinite Systems and the Voter Model", 1975.
  3. Ercan Yildiz , Daron Acemoglu , Asuman Ozdaglar , Amin Saberi , Anna Scaglione, "Discrete Opinion Dynamics with Stubborn Agents", 2011
  4. Abhimanyu Das, Sreenivas Gollapudi, and Kamesh Munagala, "Modeling Opinion Dynamics in Social Networks", 2014