This is a simulator for the unified opinion dynamics framework, as developed by Adam Coates, Anthony Kleerekoper, and Liangxiu Han.
The Unified Opinion Dynamics Simulator is a Python script that allows authors to publish small kernels of Python code that correspond to “rule modules”.
The simulator is executed by calling the main() method within main.py with one argument - a list of arguments in the standard command-line format. If run standalone, this executes one experiment I was recently running, as an example. It is suggested to use the -c [config] argument to specify a configuration file.
Options are loaded from arguments passed to main, a file passed via the -c argument, and default.cfg, in that order of precedence. For a command-line option to be recognized, it must be initialized in a configuration file as well. This is a technical limitation I intend to fix in the future.
Algorithms are invoked in the following order:
A selection of algorithms - all those I have used to date - is provided for use.
These algorithms make frequent use of two arguments, graph and opts.
Graph is the object representing the current network of agents, as described within the Networkx documents.
Opts is an object containing the current options, which can be accessed via property access: for example, opts.initial.uncertainty.
As these objects are passed around by reference, modifications to them will be persistent and seen by other rule modules.
Below, peculiarities to each will be discussed.
Must define two functions, analyse(graph, opts, chosen) and final_analysis(graph, opts).
Chosen is the last returned value of the Group rule module’s invocation.
Neither of these functions need return anything, but should probably write to a file if you want to keep your results.
Must define a function, make_graph(opts).
This function must return a Networkx graph object.
Must define a function, select_agents(graph, opts).
This function must return a tuple of two lists of integers. In the update module, nodes with IDs in the first list are acted upon by those nodes with IDs in the second list. An agent may appear in both lists.
Must define a function, set_initial(graph, opts).
This function must return a dictionary with a key named “opinion”, as well as any other keys. These keys must have as their value a list of any objects. Agents will have the initial properties set such that for agent n, that agent’s opinion is found by looking up [“opinion”][n] in this dictionary.
Must define a function, intervene(graph, opts).
This function need not return anything. It is expected to perform some manipulation on the graph such as deleting nodes or edges, but is not required to do so.
Must define a function, make_layout(graph, opts, layout).
This function must return a Networkx layout. The layout parameter may be a Networkx layout, but is usually None.
Must define a function, perform_update(graph, opts, agents).
This method need not return anything. It is expect to update graph.values[“opinion”] for the nodes in one or both lists in the agents parameter, generated by invoking the group rule module.