Continuous Opinion Dynamics under Bounded Confidence

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.

powered by NetLogo

view/download model file: bc.nlogo

Continuous Opinion Dynamics under Bounded Confidence


A model of continuous opinion dynamics under bounded confidence, which includes



In a nutshell

Agents adjust their opinion gradually towards the opinions of others when the distance in opinion is within their bound of confidence. Sometimes agents change their opinion to a new one at random. When agents hold extremal opinions they might get extremists which never adjust opinions.


Each of N agent has its opinion between 0.0 and 1.0 as a dynamic variable and its bound of confidence (eps) as a static variable. Other static variables are global and regard the type of communication and aggregation, the probability of random reset of opinion and the type and size of extremism zones.


Each agent is assigned its initial opinion as a random number between 0.0 and 1.0 from the uniform distribution. Each agent is assigned its bound of confidence as a random number form a beta-distribution between min_eps and max_eps.


Each tick agents are asked to adjust their opinions with respect to the opinions of others and their bound of confidence (eps).

1. Communication and aggregation:

2. Probability of random opinion reset

After the update of opinion each agent is asked to select a new opinion (in the same way as its initialization) but only with probability given by the variable entry_exit_rate.

3. Heterogeneous bounds of confidence

Notice that under heterogeneous bounds of confidence it might be that one agent has confidence in another but not vice versa!

4. Extremists

Extremism zones are intervals in the opinion space from 0.0 to 1.0 which are determined by the parameter extremism_range. The extremism intervals are from 0.0 to extremism_range for the selection “one side” and additionally from 1.0-extremism_range to 1.0 for the selection “two side”. Agents which are located in the extermism zone never change their opinion. But still other non-extremist agents might adjust their opinion with respect to the opinions of extremists. Extremists still undergo change of opinion due to random reset of opinions.


Click “setup” to inititialize agents with opinions random and uniformly distributed between 0.0 and 1.0. Agents are located at the left border of the world with their opinions spreading over the vertical axis. Further, on confidence bounds are initialized for each agent as random draws from a beta distribution under the current choice of the four parameters.

Click “go” to start the simulation. Agents move with ticks from left to right, displaying their opinion with the position on the vertical axis. This goes over into a “rolling” graphic in the world, where the last 120 ticks are shown (respectively the last max-pxcor ticks). Visualization can be chosen as trajectories of agents or as color-coded histograms. In colored histograms each patch’s color is associated to the number of agents at this patch.

A change of the variables communication regime, original, aggregation_in_HK, entry_exit_rate, extremism_range, and extremism_type is immediately effective in a running simulation.

A change of the variable number_of_agents immediately changes the color axis in the “Colored histogram over time”-visualization and the vertical axis in the histogram of current opinions.

A change of the four parameters of the distribution of eps (min_eps, max_esp, alpha, beta) immediately effect only the plot of the pdf of the distribution, but not the eps in the running simulation (click “new_confidence_bounds” for this).

Click “new_confidence_bounds” to make new random draws for eps for each agent. Draws come from the beta distribution with the current parameters. (The same procedure is called when clicking “setup”.)


Agents move towards the right-hand side of the world with one step each tick. This goes over into a “rolling” plot.

Notice how agents form clusters in the opinion space. See how these clusters evolve, drift and unite in the “Colored histograms over time”-visualization.

Look at the role of agents with different bounds of confidence in the “Agents’ trajectories”-visualization.

Look at the current distribution of opinions in the bar plot histogram on the right hand side and compare it to the colored histogram (the most recent colored vertical line in the world at the right hand side).

Look how the mean and the median opinion evolve over time. The mean represents the center of mass of the distribution (cf. the current histogram). The median represents an unbeatable opinion under pairwise majority decisions. (This holds when agents have single-peaked preferences with peaks at their opinion, cf. median voter theorem).

Look how the histogram of bounds of confidence matches the probability density function of the beta distribution when you click “new_confidence_bounds”.


Try the original models of homogeneous DW and HK communication without noise: Set entry_exit_rate to zero, min_eps and max_eps to the same value, and extremism_range to zero. See how a stable configuration of clusters evolves. Check how the number, sizes and locations of clusters depend on the bound of confidence. Try to determine critical bounds of confidence where the evolving cluster pattern changes significantly. Use the setup button to rerun with a new initial configuration.

Try to understand the impact of noise (entry_exit_rate) under homogeneous bounds of confidence: Set up a homogeneous eps (min_eps=max_eps), run the simulation and play with the entry_exit_rate slider (reasonable values are low, e.g. between 0.01 and 0.1). There are bounds of confidence, where the cluster pattern oscillates between two numbers of clusters. Under different entry_exit_rates the two patterns become differently likely.

Play with hetergeneous bounds of confidence (min_eps<max_eps) without noise (entry_exit_rate=0). Try different shapes of the distribution by manipulation of alpha and beta. Try to understand the drifting phenomena under the two communication regimes. Try to reproduce the phenomenon of “more chance for consensus under lower but heterogeneous bounds of confidence” (see Lorenz 2010): Set N=500, DW communication, original=off, entry_exit_rate=extremism_range=0, alpha=beta=0.1, min_eps=0.24, max_eps=0.24. See by several runs (repeatedly click “setup”) that consensus is not (or very rarely) possible. Now set min_eps=0.1 and see that the bimodal distribution (half of the population with eps=0.1 and half with eps=0.24) makes it possible that almost all agents unite in a single cluster. Beware, this does not happen all the time and might takes a lot of time (rerun and wait!). The phenomenon is better understood in the “Agents’ trajectories”-visualization.

Play with extremism under homogeneous bounds of confidence and no noise (entry_exit_rate=0). Observe the pattern of convergence under different bounds of confidence. Under what bounds of confidence does global extremism (at one or both extremes) occur? Use small extremism ranges (between 0.01 and 0.05) and play with one or two-sided extremism. Compare to Deffuant et al 2002.

Try to find differences between the original versions of the DW and HK models and the one implemented when original=off.

Try to calibrate parameters which represent an evolution of the political landscape of opinions which looks to you as a realistic evolution of a party system (regarding location and size of opinion clusters in the left–right continuum).


Original HK and DW models
Hegselmann, R. & Krause, U. Opinion Dynamics and Bounded Confidence, Models, Analysis and Simulation Journal of Artificial Societies and Social Simulation, 2002, 5, 2
Deffuant, G.; Neau, D.; Amblard, F. & Weisbuch, G. Mixing Beliefs among Interacting Agents Advances in Complex Systems, 2000, 3, 87-98
Weisbuch, G.; Deffuant, G.; Amblard, F. & Nadal, J.-P. Meet, discuss, and segregate! Complexity, 2002, 7, 55-63

General model including HK and DW
Urbig, D.; Lorenz, J. & Herzberg, H. Opinion dynamics: The effect of the number of peers met at once Journal of Artificial Societies and Social Simulation, 2008, 11, 4

On noise:
Pineda, M.; Toral, R. & Hernandez-Garcia, E. Noisy continuous-opinion dynamics Journal of Statistical Mechanics: Theory and Experiment, 2009, 2009, P08001 (18pp)
Mäs, M.; Flache, A. & Helbing, D. Individualization as Driving Force of Clustering Phenomena in Humans PLoS Comput Biol, Public Library of Science, 2010, 6, e1000959

On heterogeneous bounds of confidence
Lorenz, J. Heterogeneous bounds of confidence: Meet, Discuss and Find Consensus! Complexity, 2010, 15, 43-52

On extremism
Deffuant, G.; Neau, D.; Amblard, F. & Weisbuch, G. How Can Extremism Prevail? A Study Based on the Relative Agreement Interaction Model Journal of Artificial Societies and Social Simulation, 2002, 5, 1
Deffuant, G. Comparing Extremism Propagation Patterns in Continuous Opinion Models Journal of Artificial Societies and Social Simulation, 2006, 9, 8

Survey, Motivation and Variation
Lorenz, J. Continuous Opinion Dynamics under bounded confidence: A Survey Int. Journal of Modern Physics C, 2007, 18, 1819-1838
Urbig, D. Attitude Dynamics with Limited Verbalisation Capabilities Journal of Artificial Societies and Social Simulation, 2003, 6, 2
Lorenz, J. & Urbig, D. About the Power to Enforce and Prevent Consensus by Manipulating Communication Rules Advances in Complex Systems, 2007, 10, 251
Amblard, F. & Deffuant, G. The role of network topology on extremism propagation with the relative agreement opinion dynamics Physica A: Statistical Mechanics and its Applications, 2004, 343, 725-738
Groeber, P.; Schweitzer, F. & Press, K. How Groups Can Foster Consensus: The Case of Local Cultures Journal of Artificial Societies and Social Simulation, 2009, 12, 4


Copyright 2012 Jan Lorenz.,

Creative Commons Attribution-ShareAlike 3.0 Unported License

This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit .


turtles-own [opinion eps opinion-list extremist?]
;; eps is the bound of confidence, opinion-list is to hold the list of the last max-pxcor opinions, extremist? checks if the turtle is in an opinion interval of extremism
globals [ current_min_eps current_max_eps current_alpha current_beta]
;; variables to display the parameters of the beta distribution from which the current eps-values are drawn
;; the slider-variables min_eps, max_eps, alpha, beta are changed to current_... when new_confidence_bounds is called


to setup
  ask patches [set pcolor white]
  create-turtles number_of_agents
  ask turtles [
    set opinion new-opinion 
    set opinion-list (list opinion)
    setxy 0 (opinion * max-pycor) 
  new_confidence_bounds ;; see procedure

to go
  ask turtles [ set opinion-list lput opinion opinion-list ] ;; put opinion after opinion-list to use it as "old" value for simulatanous update in HK
  ifelse (communication_regime = "DW (select one)") and (original = true) 
    [repeat count turtles [ask one-of turtles [ update-opinion ]]] ;; in original DW we chose N random pairs each tick
    [ask turtles [ update-opinion ]] ;; in all other versions there is an update for each agent every tick
    ;; for "update-opinion" see the procedure
  ask turtles [ set opinion-list replace-item ( length opinion-list - 1) opinion-list opinion ] ;; update the opinion-list
  ask turtles [ if (length opinion-list = max-pxcor + 1) [ set opinion-list butfirst opinion-list ] ] ;; cut oldest values for "rolling" opinion list
  ask turtles [ entry-exit ] ;; see the procedure
  draw-trajectories  ;; see the procedure

to new_confidence_bounds
  set current_min_eps min_eps
  set current_max_eps max_eps
  set current_alpha alpha
  set current_beta beta
  ask turtles [
    let x random-gamma alpha 1
    set eps ( x / ( x + random-gamma beta 1) ) ;; set eps a random number from distribution Beta(alpha,beta) (between 0 and 1)
    set eps min_eps + (eps * (max_eps - min_eps)) ;; scale and shift eps to lie between min_eps and max_eps
    set color colorcode eps 0.5 ;; see reporter colorcode


to update-opinion
  ;; detect if in extremism zone
  if (extremism_type = "two side") [set extremist? (0.5 - abs(opinion - 0.5) < extremism_range)]
  if (extremism_type = "one side") [set extremist? (opinion < extremism_range)]
  ;; change of opinion
  if (communication_regime = "DW (select one)") [
   ;; adjust opinion with random partner
   let partner one-of turtles
   if (abs (opinion - [opinion] of partner) < eps ) and (not extremist?) [
     set opinion (opinion + [opinion] of partner) / 2 
     if (original = true) [ ;; also partner updates opinion, this increases number of average activities of agents per time step from 1 to 2
       ask partner [
         if (extremism_type = "two side") [set extremist? (0.5 - abs(opinion - 0.5) < extremism_range)]
         if (extremism_type = "one side") [set extremist? (opinion < extremism_range)]         
         if (abs (opinion - [opinion] of myself) < eps ) and (not extremist?) [set opinion (opinion + [opinion] of myself) / 2] 
  if (communication_regime = "HK (select all)") [
   ;; adjust opinion to mean of all in agents closer than eps
   if not extremist? [
     ifelse (original = true) 
        [ set opinion aggregate ( filter [abs( ? - last opinion-list) < eps] [last opinion-list] of turtles ) ]
        [ set opinion aggregate ( filter [abs( ? - opinion) < eps] [opinion] of turtles ) ]
        ;; for aggregate see the reporter 

to entry-exit
  ;; randomly reset opinion with probability entry_exit_rate
  if (random-float 1 < entry_exit_rate) [set opinion new-opinion]

to draw-trajectories
  ;; let turtles move with their opinion trajectories from left to right across the world drawing trajectories or coloring patches
  ask turtles [
    setxy 0 (item 0 opinion-list * max-pycor)
  ifelse (visualization = "Colored histogram over time") [ ask turtles [ pen-up ] ] [ask turtles [ pen-down ] ]
  let t-counter 1
  while [ t-counter < (length ( [opinion-list] of turtle 1 )) ] [ 
    ask turtles [setxy t-counter (item t-counter opinion-list * max-pycor)]
    ifelse (visualization = "Colored histogram over time") 
      [ ask patches with [pxcor = t-counter ] [ set pcolor colorcode ((count turtles-here) / number_of_agents) 0.2 ] ] ;; see reporter colorcode
      [ ask patches [ set pcolor white ] ]
    set t-counter t-counter + 1 


to-report new-opinion
  report random-float 1

to-report aggregate [opinions]
   if (aggregation_in_HK = "mean") [report mean opinions]
   if (aggregation_in_HK = "median") [report median opinions]

to-report colorcode [x max_x]
  ;; report a color as "x=0 --> violet", "x=max_x --> red" on the color axis violet,blue,cyan,green,yellow,orange,red 
  report hsb (190 - 190 * (x / max_x)) 255 255

;; Copyright 2012 Jan Lorenz
;; See Info tab for full copyright and license