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:
- A subdirectory named `/images`, where static network visualizations at each epoch will be stored.
- A file named `/buyers.csv`, where information about buyers (their current item, intention, etc.) will be recorded.
- A file named `/graphs.csv`, where information about the network will be recorded.
- 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 objects track market states throughout experiments for future analysis. |
| Function | count |
Counts the number of edges between buyers of different communities. |
| Function | get |
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 |
Gets distribution of buyers and purchased items in a community. The returned distribution graph is of the following form: |
| Function | get |
Returns a list of the names of the communities in a market. |
| Function | get |
Returns min, max, and mean of node degrees in the graph. |
Counts the number of edges between buyers of different communities.
| Parameters | |
| graph | graph representing current market state |
| Returns | |
| number of edges between buyers of different communities | |
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 | |
| graph | graph representing current market state |
| buyer | target buyer |
| mac | Undocumented |
| Returns | |
| eigenvector and betweenness centrality for target buyer | |
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 | |
| graph | graph representing current market state |
| Returns | |
| tiered dictionary of purchase distributions across communities | |
Returns a list of the names of the communities in a market.
| Parameters | |
| graph | graph representing current market state |
| Returns | |
| list of names of communities in the graph | |