Skip to main content

vame.analysis.tree_hierarchy

Variational Animal Motion Embedding 1.0-alpha Toolbox © K. Luxem & P. Bauer, Department of Cellular Neuroscience Leibniz Institute for Neurobiology, Magdeburg, Germany

https://github.com/LINCellularNeuroscience/VAME Licensed under GNU General Public License v3.0

hierarchy_pos

def hierarchy_pos(G: nx.Graph,
root: str | None = None,
width: float = 0.5,
vert_gap: float = 0.2,
vert_loc: float = 0,
xcenter: float = 0.5) -> Dict[str, Tuple[float, float]]

Positions nodes in a tree-like layout. Ref: From Joel's answer at https://stackoverflow.com/a/29597209/2966723.

Arguments:

  • G nx.Graph - The input graph. Must be a tree.
  • root str, optional - The root node of the tree. If None, the function selects a root node based on graph type.
  • width float, optional - The horizontal space assigned to each level.
  • vert_gap float, optional - The vertical gap between levels.
  • vert_loc float, optional - The vertical location of the root node.
  • xcenter float, optional - The horizontal location of the root node.

Returns:

Dict[str, Tuple[float, float]]: A dictionary mapping node names to their positions (x, y).

merge_func

def merge_func(transition_matrix: np.ndarray, n_cluster: int,
motif_norm: np.ndarray,
merge_sel: int) -> Tuple[np.ndarray, np.ndarray]

Merge nodes in a graph based on a selection criterion.

Arguments:

  • transition_matrix np.ndarray - The transition matrix of the graph.
  • n_cluster int - The number of clusters.
  • motif_norm np.ndarray - The normalized motif matrix.
  • merge_sel int - The merge selection criterion.
    • 0: Merge nodes with highest transition probability.
    • 1: Merge nodes with lowest cost.

Raises:

  • ValueError - If an invalid merge selection criterion is provided.

Returns:

Tuple[np.ndarray, np.ndarray]: A tuple containing the merged nodes.

graph_to_tree

def graph_to_tree(motif_usage: np.ndarray,
transition_matrix: np.ndarray,
n_cluster: int,
merge_sel: int = 1) -> nx.Graph

Convert a graph to a tree.

Arguments:

  • motif_usage np.ndarray - The motif usage matrix.
  • transition_matrix np.ndarray - The transition matrix of the graph.
  • n_cluster int - The number of clusters.
  • merge_sel int, optional - The merge selection criterion. Defaults to 1.
    • 0: Merge nodes with highest transition probability.
    • 1: Merge nodes with lowest cost.

Returns:

  • nx.Graph - The tree.

draw_tree

def draw_tree(T: nx.Graph) -> None

Draw a tree.

Arguments:

  • T nx.Graph - The tree to be drawn.

Returns:

None

traverse_tree_cutline

def traverse_tree_cutline(T: nx.Graph,
root_node: str | None = None,
cutline: int = 2) -> List[List[str]]

Traverse a tree with a cutline and return the community bags.

Arguments:

  • T nx.Graph - The tree to be traversed.
  • root_node str, optional - The root node of the tree. If None, traversal starts from the root.
  • cutline int, optional - The cutline level.

Returns:

  • List[List[str]] - List of community bags.