Community Assembly Graphs
Community assembly graphs are an ecological tool that can be repurposed to understand possible evolutionary trajectories for populations under selection schemes that create complex ecology.
- ec_ecology_toolbox.community_assembly_graph.CAG(start_node, user_func, num_nodes=10, normalize_w_self_edges=False, num_iterations=1500)
Main function that is used to explore the graph based on user function and start node Graph is explored based on continuous probability of reaching a node signified by edge weights Probability of reaching a node calculated from user given start node User defines the bumber of nodes to be discoered and returned
- Parameters:
start_node (user-defined Node class) – starting node of exploration
user_func (function) – user defined function the returns all outgoing edges with weights from input node
num_nodes (int) – number of nodes to explore
normalize_w_self_edges (bool) – normalize nodes by including self edges if True. default: False
num_iterations (int) – number of iterations to run for random walk. default: 100
- Returns:
explored graph until required number of nodes reached or full graph is explored
- Return type:
dict {Node: dict {Node: float}}
- class ec_ecology_toolbox.community_assembly_graph.Chr_Node(*args)
Sample class for user defined Node in graphs Nodes are characterized based on a single character e.g. integers Equality of nodes are based on having the same character Inequality is compared using number values if integers, ASCII values if string character Node class is hashable
- __init__(*args)
- class ec_ecology_toolbox.community_assembly_graph.Set_Node(*args)
Sample class for user defined Node in graphs Nodes are characterized based on a set of elements Equality of nodes are based on having the same set of elements Inequality is compared using length of the set i.e. number of elements in the set Node class is hashable and uses frozen sets
- __init__(*args)
- ec_ecology_toolbox.community_assembly_graph.random_walk_matrix_multiplication(graph, start_node, num_iterations)
Function used to calculate probabilities of ending up at a node i.e. node passing probability Implements iterative random walk theory using matrix multiplication Refer: https://chih-ling-hsu.github.io/2020/05/20/random-walks
- Parameters:
graph (dict {Node: dict {Node: float}}) – manipulated graph with sink nodes on which the random walk algorithm is run
start_node (user-defined Node class) – the start node of the random walk
num_iterations (int) – number of iterations to run for the random walk. default: 100
- Returns:
tuple including final passing probabilities after convergence and the node directory for index matching
- Return type:
tuple (list [float], dict {Node: int})
- ec_ecology_toolbox.community_assembly_graph.update_priorities(graph, leaves, start_node, node_passing_p, num_iterations)
Updates the probabilities of the discovered nodes in the priority queue Called when new paths to visited nodes or cycles are discovered in the explored graph
- Parameters:
graph (dict {Node: dict {Node: float}}) – explored graph with all visited nodes and discovered paths
leaves (set {Node}) – all leaf nodes that have been discovered and are in the priority queue
start_node (user-defined Node class) – the starting node of exploration
node_passing_p (dict {Node: float}) – holds the updated passing probability of all discovered nodes
num_iterations (int) – number of iterations to run for the random walk. default: 100
- Returns:
new priority queue with updated probabilities of all leaf nodes
- Return type:
queue.PriorityQueue -> tuple (float, Node)