Welcome to the documentation for the quoter-model package
Table of contents to be added later
Please also excuse some docstrings being badly formatted - it is in the TODO!
See below for the function references inside the quoter package (listed as quoter-model on pypi). The package’s repository can be found at https://github.com/jsm8989/quoter/
quoter_model module
- quoter.quoter_model.edge_clustering_coeff(G: Graph, node_u: int, node_v: int, return_info: bool = False, draw: bool = False)
Compute ECC between two nodes node_u and node_v, defined as the number of triangles containing both node_u and node_v divided by min(degrees(node_u,node_v))-1
- Args:
G: NetworkX graph to be analysed. Must be directed node_u: node index of first node node_v: node index of second node return_info: if True return information about the algorithm draw: choose whether to visualise the graph
- Returns:
triangles deg_u deg_v ECC (if return_info) ECC
- quoter.quoter_model.get_modularity(G, community_dict)
Calculate the modularity. Edge weights are ignored. From https://github.com/zhiyzuo/python-modularity-maximization/blob/master/modularity_maximization/utils.py
- Parameters:
G – NetworkX graph to be analysed
community_dict – A dict to store the membership of each node. Key is node and value is community index
- Returns:
(float) The modularity of G given community_dict
- quoter.quoter_model.quoter_model_sim(G: ~networkx.classes.graph.Graph, quote_prob: float, timesteps: int, outdir: str = './', outfile: str = 'test_output.txt', write_data=<function write_all_data>, dunbar: int | None = None, verbose: bool = False, SBM_graph: bool = False, poisson_lambda: float | int = 3, startWords=20)
Simulate the quoter model on a graph G. Nodes take turns generating content according to two mechanisms: (i) creating new content from a specified vocabulary distribution, (ii) quoting from a neighbor’s past text.
[1] Bagrow, J. P., & Mitchell, L. (2018). The quoter model: A paradigmatic model of the social flow of written information. Chaos: An Interdisciplinary Journal of Nonlinear Science, 28(7), 075304.
- Args:
G (nx.Graph): Directed graph to simulate quoter model on quote_prob (float): Quote probability q as defined in [1] timesteps (int): Number of time-steps to simulate for. timesteps=1000 really means 1000*nx.number_of_nodes(G), i.e. each node will have ‘tweeted’ ~1000 times outdir (string): Name of directory for data to be stored in outfile (string): Name of file for this simulation write_data (function): Can specify what data to compute & write. dunbar (int or None): If int, limit in-degree to dunbar’s number verbose: <temp> giving useful output during testing
- TODO: add args from other previous experiments, such as
lambda (quote length > 0) - from q-lambda [added as poisson_lambda] alpha_alter, alpha_ego - from theory_link and potentially others
- Returns:
G, once the simulation has been run, to pass to some other writing/calculation function
- quoter.quoter_model.words_to_tweets(words: Iterable, times: Iterable)
Convert (words,times) array to a smaller array of (tweets,times)
- Parameters:
words – A list of words. Each word is a list of word tokens.
times – A list of times. Each time it is called the words will be compared to each other to see if they are the same.
- Returns:
A list of tuples where each tuple is a tweet
- quoter.quoter_model.write_all_data(G: Graph, outdir: str, outfile: str, SBM: bool = False, verbose: bool = False, swap_quote_direction_lower_hx: bool = False, skip_edges: bool = False, skip_nodes: bool = False, skip_graph: bool = False)
Compute and write data from quoter model simulations. TODO: This feels like it should be split up more. Also make sure the outdir exists or create it if needed.
- Args:
G (nx.Graph): _description_ outdir (str): _description_ outfile (str): _description_
real_networks.read_networks module
- quoter.real_networks.read_networks.get_giant_component(G)
Returns the giant component of a graph. Giant components are nodes that are connected to each other in the graph.
@param G - NetworkX graph to be analysed. It must be directed.
@return G with only the giant component removed. This is a copy of G
- quoter.real_networks.read_networks.get_modularity(G, community_dict)
Calculate the modularity. Edge weights are ignored. From https://github.com/zhiyzuo/python-modularity-maximization/blob/master/modularity_maximization/utils.py
- Parameters:
G – NetworkX graph to be analysed
community_dict – A dict to store the membership of each node. Key is node and value is community index
- Returns:
(float) The modularity of G given community_dict
- quoter.real_networks.read_networks.read_Eu_Core()
Read Eu-Core NetworkX file and return giant component.
- Returns:
networkx graph
- quoter.real_networks.read_networks.read_Freemans(network_num=1)
Read Freemans network
- Parameters:
network_num – The index of the network to read
- Returns:
networkx graph
- quoter.real_networks.read_networks.read_adolescent()
Read adolescent_health file and return networkx graph. This file is used to determine the health of the network and should contain a list of tuples ( node_id node_name ) where node_id is the node id of the node that is connected to the node with the same node_name.
- Returns:
NetworkX graph
- quoter.real_networks.read_networks.read_arxiv_CondMat()
Read Arxiv Cond Mat file and return Giant component.
- Returns:
Graph with components as node ids
- quoter.real_networks.read_networks.read_arxiv_GrQc()
Read GrQc file and return giant component. It is assumed that the file is in arxiv format
- Returns:
networkx graph with components as node ids
- quoter.real_networks.read_networks.read_ckm(network_num=3)
Read CKM physicians from file. This file is used to generate network connectivity matrices and other data structures that can be used for testing.
- Parameters:
network_num – ( int ) number of network 1 2 or 3
- Returns:
( NetworkX ) network connectivity matrices and other data
- quoter.real_networks.read_networks.read_dolphins()
Read dolphins file and return networkx graph.
- Returns:
networkx graph
- quoter.real_networks.read_networks.read_email()
Read email network and return networkx graph.
- Returns:
NetworkX graph with email network
- quoter.real_networks.read_networks.read_enron()
Read and return enron network. 10588 nodes; 65901 edges (directed) and 54527 (undirected). We use the undirected graph.
- Returns:
Giant component of the NetworkX graph
- quoter.real_networks.read_networks.read_hypertext()
This network is a DYNAMIC network (edges are timestamped). We are treating it as static (a link is present if a link existed at any time).
CrossEntropyLocal module
This should not be needed, but is included as a local solution in case of issues with installing the remote package.
Due to install issues, it is easier to consult the ProcessEntropy package here for documentation. (for now)
Examples using the quoter-model package
Possible ways of simulating the quoter model on networks can be found in quoter.examples`
These are intended to be run from any directory once the package has been installed, and will write results to an ouput/ directory relative to this one.
After running simulations, summary statistics can be processed using scripts inside quoter.examples.processing