mdx.behavior_learning.nn.behavior_clustering module

class BehaviorClustering(config)

Bases: object

Module to generate clustering labels for behavior data.

Parameters:

config (dict) – configuration for the module

behavior_clustering = BehaviorClustering(config)
directed_hausdorff(behavior_df)

Calculates the directed hausdorff distance with each behavior as its own space.

Parameters:

behavior_df (pandas.Dataframe) – pandas data frame containing behavior data.

Returns:

Returns the pairwise directed distance matrix as an array.

Return type:

numpy.ndarray

hausdorff_dist_matrix = behavior_clustering.directed_hausdorff(behavior_data)
generate_labels(behavior_df)

Generates clustering labels for the behavior data. Calculates the cuSpatial directed hausdorff distance between trajectories contained in the behavior data and uses them as input to HDBSCAN to cluster behavior. Makes calls to directed_hausdorff() and run_HDBSCAN(). Parameters for clustering are taken from the config file.

Parameters:

behavior_df (pandas.Dataframe) – pandas data frame containing behavior data.

Returns:

Input dataframe with an additional column ‘labels’, that contains the cluster labels. Also returns number of clusters and noisy points.

Return type:

(pandas.DataFrame, int, int)

labelled_data, num_clusters, num_noise = behavior_clustering.generate_labels(behavior_data)
get_clustering_info(labels)

Returns number of clusters and number of noisy points.

Parameters:

labels (list) – labels to be counted.

Returns:

tuple of ints

Return type:

(int, int)

num_clusters, num_noise = behavior_clustering.get_clustering_info(lables)
run_HDBSCAN(dist_matrix, sensor)

Clusters the behavior using HDBSCAN and returns labelled data with respective clustering. Labels for the behaviors are returned in the same order as they exist in the dist_matrix. Parameters min_cluster_size, min_samples for HDBSCAN are taken from config file.

Parameters:
  • dist_matrix (numpy.ndarray) – directed hausdorff distance matrix of behaviors that are to be clustered.

  • sensor (string) – sensor id corresponding to the dist_matrix, required for reading sensor specific configuration.

Returns:

Returns a list of labels.

Return type:

list

labels = behavior_clustering.run_HDBSCAN(distance_matrix);
update_config(new_config)

Updates the config of the module with the user provided config.

Parameters:

new_config (dict) – new config for update.

Returns:

none

behavior_clustering.update_config(new_config)