Skip to main content

vame.analysis.community_analysis

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

Updated 5/11/2022 with PH edits

get_adjacency_matrix

def get_adjacency_matrix(
labels: np.ndarray,
n_cluster: int) -> Tuple[np.ndarray, np.ndarray, np.ndarray]

Calculate the adjacency matrix, transition matrix, and temporal matrix.

Arguments:

  • labels np.ndarray - Array of cluster labels.
  • n_cluster int - Number of clusters.

Returns:

Tuple[np.ndarray, np.ndarray, np.ndarray]: Tuple containing adjacency matrix, transition matrix, and temporal matrix.

get_transition_matrix

def get_transition_matrix(adjacency_matrix: np.ndarray,
threshold: float = 0.0) -> np.ndarray

Compute the transition matrix from the adjacency matrix.

Arguments:

  • adjacency_matrix np.ndarray - Adjacency matrix.
  • threshold float, optional - Threshold for considering transitions. Defaults to 0.0.

Returns:

  • np.ndarray - Transition matrix.

find_zero_labels

def find_zero_labels(motif_usage: Tuple[np.ndarray, np.ndarray],
n_cluster: int) -> np.ndarray

Find zero labels in motif usage and fill them.

Arguments:

  • motif_usage Tuple[np.ndarray, np.ndarray] - 2D list where the first index is a unique list of motif used and the second index is the motif usage in frames.
  • n_cluster int - Number of clusters.

Returns:

  • np.ndarray - List of motif usage frames with 0's where motifs weren't used (array with zero labels filled).

augment_motif_timeseries

def augment_motif_timeseries(label: np.ndarray,
n_cluster: int) -> Tuple[np.ndarray, np.ndarray]

Augment motif time series by filling zero motifs.

Arguments:

  • label np.ndarray - Original label array.
  • n_cluster int - Number of clusters.

Returns:

Tuple[np.ndarray, np.ndarray]: Augmented label array and indices of zero motifs.

get_labels

def get_labels(cfg: dict, files: List[str], model_name: str, n_cluster: int,
parametrization: str) -> List[np.ndarray]

Get cluster labels for given videos files.

Arguments:

  • cfg dict - Configuration parameters.
  • files List[str] - List of video files paths.
  • model_name str - Model name.
  • n_cluster int - Number of clusters.
  • parametrization str - parametrization.

Returns:

  • List[np.ndarray] - List of cluster labels for each file.

get_community_label

def get_community_label(cfg: dict, files: List[str], model_name: str,
n_cluster: int, parametrization: str) -> np.ndarray

Get community labels for given files.

Arguments:

  • cfg dict - Configuration parameters.
  • files List[str] - List of files paths.
  • model_name str - Model name.
  • n_cluster int - Number of clusters.
  • parametrization str - parametrization.

Returns:

  • np.ndarray - Array of community labels.

compute_transition_matrices

def compute_transition_matrices(files: List[str], labels: List[np.ndarray],
n_cluster: int) -> List[np.ndarray]

Compute transition matrices for given files and labels.

Arguments:

  • files List[str] - List of file paths.
  • labels List[np.ndarray] - List of label arrays.
  • n_cluster int - Number of clusters.

Returns:

  • List[np.ndarray] - List of transition matrices.

create_community_bag

def create_community_bag(files: List[str], labels: List[np.ndarray],
transition_matrices: List[np.ndarray], cut_tree: int,
n_cluster: int) -> Tuple

Create community bag for given files and labels (Markov chain to tree -> community detection).

Arguments:

  • files List[str] - List of file paths.
  • labels List[np.ndarray] - List of label arrays.
  • transition_matrices List[np.ndarray] - List of transition matrices.
  • cut_tree int - Cut line for tree.
  • n_cluster int - Number of clusters.

Returns:

  • Tuple - Tuple containing list of community bags and list of trees.

create_cohort_community_bag

def create_cohort_community_bag(labels: List[np.ndarray],
trans_mat_full: np.ndarray, cut_tree: int,
n_cluster: int) -> Tuple

Create cohort community bag for given labels, transition matrix, cut tree, and number of clusters. (markov chain to tree -> community detection)

Arguments:

  • labels List[np.ndarray] - List of label arrays.
  • trans_mat_full np.ndarray - Full transition matrix.
  • cut_tree int - Cut line for tree.
  • n_cluster int - Number of clusters.

Returns:

  • Tuple - Tuple containing list of community bags and list of trees.

get_community_labels

def get_community_labels(
files: List[str], labels: List[np.ndarray],
communities_all: List[List[List[int]]]) -> List[np.ndarray]

Transform kmeans parameterized latent vector into communities. Get community labels for given files and community bags.

Arguments:

  • files List[str] - List of file paths.
  • labels List[np.ndarray] - List of label arrays.
  • communities_all List[List[List[int]]] - List of community bags.

Returns:

  • List[np.ndarray] - List of community labels for each file.

get_cohort_community_labels

def get_cohort_community_labels(
files: List[str], labels: List[np.ndarray],
communities_all: List[List[List[int]]]) -> List[np.ndarray]

Transform kmeans parameterized latent vector into communities. Get cohort community labels for given labels, and community bags.

Arguments:

  • files List[str], deprecated - List of file paths.
  • labels List[np.ndarray] - List of label arrays.
  • communities_all List[List[List[int]]] - List of community bags.

Returns:

  • List[np.ndarray] - List of cohort community labels for each file.

community

@save_state(model=CommunityFunctionSchema)
def community(config: str,
parametrization: Parametrizations,
cohort: bool = True,
cut_tree: int | None = None,
save_logs: bool = False) -> None

Perform community analysis.

Arguments:

  • config str - Path to the configuration file.
  • cohort bool, optional - Flag indicating cohort analysis. Defaults to True.
  • cut_tree int, optional - Cut line for tree. Defaults to None.

Returns:

None