module documentation

This module implements the Logger class and its supporting methods. The Logger class is the key to accessing results from social network experiments without writing any analysis code in Python.

RESULTS FILES

At construction, a directory path is provided to the Logger object. Inside this directory, Logger creates the following:

  1. A subdirectory named `/images`, where static network visualizations at each epoch will be stored.
  2. A file named `/buyers.csv`, where information about buyers (their current item, intention, etc.) will be recorded.
  3. A file named `/graphs.csv`, where information about the network will be recorded.
  4. A file named `/matrix.csv`, where information about communities will be recorded.

`matrix.csv` records the number of edges between each pair of communities (hence, it is a matrix).

In addition, experimental metadata is recorded in an info file at the beginning of any experiment (see: scalefree.py and smallworld.py).

TIMESTAMPS

The Logger object records the market state at every timestamp. A timestamp is a tuple that contains an epoch and a timestep.

An epoch is every iteration of market purchases. One set of purchasing, rewiring, and changing buyer intentions is an epoch. You can set the number of desired epochs when instantiating the experiment.

Timesteps work differently depending on the experiment type. In a small world experiment, a timestep is every instance that the graph considers an edge for rewiring. If there are `m` edges in the graph, there will be `m` timesteps in each epoch. In a scale free experiment, a timestep is every instance that the graph considers a node for random reassignment of purchase intention. If there are `n` nodes in the graph, then there will be `n` timesteps in each epoch.

MAC OS USERS

Eigenvector centrality as implemented through NetworkX has limited functionality on MacOS. If you encounter an error when computing eigenvector centrality, change the default parameter `macOS` in the `get_buyer_community_centralities` method to `True`. For convenience, this is the first method in the file.

Class Logger Logger objects track market states throughout experiments for future analysis.
Function count_community_connections Counts the number of edges between buyers of different communities.
Function get_buyer_community_centralities Returns the eigenvector and betweenness centralities for a particular buyer. Note: Eigenvector centrality as implemented through NetworkX has limited functionality on MacOS. You can change the above default parameter to True to avoid computing eigenvector centrality...
Function get_community_distributions Gets distribution of buyers and purchased items in a community. The returned distribution graph is of the following form:
Function get_community_names Returns a list of the names of the communities in a market.
Function get_degree_stats Returns min, max, and mean of node degrees in the graph.
def count_community_connections(graph):

Counts the number of edges between buyers of different communities.

Parameters
graphgraph representing current market state
Returns
number of edges between buyers of different communities
def get_buyer_community_centralities(graph, buyer, macOS=False):

Returns the eigenvector and betweenness centralities for a particular buyer. Note: Eigenvector centrality as implemented through NetworkX has limited functionality on MacOS. You can change the above default parameter to True to avoid computing eigenvector centrality. If macOS is set to True, eigen_centrality will be returned as -1000.

Parameters
graphgraph representing current market state
buyertarget buyer
macOSUndocumented
Returns
eigenvector and betweenness centrality for target buyer
def get_community_distributions(graph):

Gets distribution of buyers and purchased items in a community. The returned distribution graph is of the following form:

  • Key: community names, Value: [integer, dictionary2]
  • Key2: purchased item, Value2: number of buyers that purchased that item
Parameters
graphgraph representing current market state
Returns
tiered dictionary of purchase distributions across communities
def get_community_names(graph):

Returns a list of the names of the communities in a market.

Parameters
graphgraph representing current market state
Returns
list of names of communities in the graph
def get_degree_stats(graph):

Returns min, max, and mean of node degrees in the graph.

Parameters
graphgraph representing current market state
Returns
min, max, and mean of node degrees in the graph