Analyze
- utils.analyze.BORIS_to_pose(config, verbose=True)[source]
Intake paired BORIS one-hot-encoded observation files and pose segmented files and align them to see what behaviors line up with what pose modules
- Parameters:
config – the config
- Returns:
- utils.analyze.classify(module_feature_object, method='lda')[source]
Classify pose segmentation data using either module usage or transitions
- Parameters:
module_feature_object – ModuleUsage or ModuleTransitions object
method – classification method to use; options include “lda”, “logisticregression”, “mlp”, “naivebayes”, “knn”, or “randomforest”
- Returns:
classifier
- utils.analyze.combine_pose_modules(config, labels_df, force_no_numeric=False)[source]
Combine pose modules based on remappings key in config
- Parameters:
config – config
labels_df – from label_counter (subgroups or no_subgroups)
- Returns:
labels_df_remapped
- utils.analyze.ego_center(config, data, keypoint_ego1, keypoint_ego2)[source]
Ego centering a single pose estimation dataframe
- Parameters:
config – config
data – pose estimation pandas dataframe in DLC format
keypoint_ego1 – first keypoint to use for establishing egocentric alignment axis
keypoint_ego2 – second keypoint to use for establishing egocentric alignment axis
- Returns:
ego_centered pandas dataframe
- utils.analyze.embed(module_feature_object, method='lda', n_components=2)[source]
Get dimensionally reduced space embeddings of the data with LDA or PCA
- Parameters:
module_feature_object – module feature object
method – LDA or PCA; default LDA
n_components – number of components
- Returns:
- utils.analyze.get_action_units(config, start, end, binsize=None, selected_subgroups=None, aus_to_include='all')[source]
Function for getting mean action units :param config: project config :param start: start time (in s) :param end: end time (in s) :param binsize: optional - temporal bin size (default None for no binning) :param selected_subgroups: otpional - selected subgroups :param aus_to_include: list of integers corresponding to action units to include, or “all” for all; default “all” :return: ActionUnits
- utils.analyze.get_distance(module_feature_object, method='euclidean')[source]
Get distance
- Parameters:
module_feature_object –
method –
- Returns:
- utils.analyze.get_keypoint_kinematics(PE_config, keypoint_ego1, keypoint_ego2, start, end, binsize=None, metric='angle', thresh=70, selected_subgroups='all', return_as_df=True, verbose=False)[source]
Measure keypoint kinematics (egocentrically aligned angle, distance, and travel of keypoints) across group of subjects
- Parameters:
PE_config – pose estimation config - used for FPS only
keypoint1 – first keypoint to use for establishing egocentric alignment axis
keypoint2 – second keypoint to use for establishing egocentric alignment axis
start – start time in seconds
end – end time in seconds
binsize – if binned output is desired, size of timebins (default is None for no binning)
metric – metric to assess for all non-keypoint1/2 keypoints; options are “angle_m” (for mean angle), “angle_sd” (for std deviation of angle), “distance_m” (for mean distance of keypoints to ego-center), “distance_sd” (for std deviation of distance of keypoints to ego-center), or “travel” (for movement of keypoints relative to ego-center)
thresh – threshold for when distance ‘jump’ is too large and should be excluded; default 70
selected_subgroups – subgroups to analyze as defined in config; default “all”
return_as_df – return as a dataframe or return as KeypointTravel class (for embedding, classification)
- Returns:
- utils.analyze.get_keypoint_travel(PE_config, keypoint, start, end, binsize=None, thresh=70, selected_subgroups='all', return_as_df=True)[source]
Measure keypodint distance travelled across group of subjects
- Parameters:
PE_config – pose estimation config - used for FPS only
keypoint – name of keypoint
start – start time in seconds
end – end time in seconds
binsize – if binned output is desired, size of timebins (default is None for no binning)
thresh – threshold for when distance ‘jump’ is too large and should be excluded; default 70
selected_subgroups – subgroups to analyze as defined in config; default “all”
return_as_df – return as a dataframe or return as KeypointTravel class (for embedding, classification)
- Returns:
- utils.analyze.get_module_labels(config, start, stop, subgroups=None)[source]
Generates a Pandas dataframe containing the labels for every frame in the specified time range for the video paths in defined groups.
- Parameters:
config – the config
start – time in seconds to start dataframe from.
stop – time in seconds to stop dataframe at.
fps – frames per second of recording.
subgroups – subgroups to include; by default, None will result in an object without data subgrouped; could alternatively be a list of subgroup names from config or “all” (to include all subgroups present in config)
- Returns:
labels dataframe
- utils.analyze.get_module_transitions(config, labels_df, modules_altered=False)[source]
Reshape labels dataframe from label_counter_subgroups to be an array of features
- Parameters:
config – config object
labels_df – labels dataframe from label_counter_subgroups
binsize – width of bins in seconds; if None, no binning is performed
- Returns:
- utils.analyze.get_module_usage(config, labels_df, binsize=None, modules_altered=False)[source]
Reshape labels dataframe from label_counter_subgroups to be an array of features
- Parameters:
config – config object
labels_df – labels dataframe from label_counter_subgroups
binsize – width of bins in seconds; if None, no binning is performed
modules_altered – must be true if modules have been remapped
- Returns:
object of class ModuleUsage
- utils.analyze.loocv(module_feature_object, method='lda')[source]
Perform leave-one-out cross-validation for a method of classifying pose segmentation data using either module usage or transitions
- Parameters:
module_feature_object – ModuleUsage or ModuleTransitions object
method – classification method to use; options include “lda”, “logisticregression”, “mlp”, “naivebayes”, “knn”, or “randomforest”
- Returns:
accuracy, conf_mat
- utils.analyze.loocv_regression(module_feature_object, dose_dict, method='LinearRegression', constrain_pos=True, degree=1, alpha=1)[source]
Perform LOOCV for linear regression
- Parameters:
module_feature_object – ModuleUsage, ModuleTransitions, or KeypointFeature object
dose_dict – dictionary with keys corresponding to subgroups and items corresponding to variable
method – method of regression; either “LinearRegression” (default) or “Ridge” or “Lasso”
constrain_pos – constrain to only positive values; true by default
degree – degree of polynomial (default 1)
alpha – alpha (default 1; only applies for regularized regression, i.e. Ridge and Lasso)
- Returns:
held-out predictions, squared error
- utils.analyze.make_remappings_from_BORIS(config, labels_df=None, BORIS_to_pose_mat=None, force_no_numeric=False)[source]
Make remappings based on BORIS output and apply to labels_df
- Parameters:
config – config
labels_df –
BORIS_to_pose_mat – the non-normalized result matrix (first result option) from BORIS_to_pose
- Returns:
- utils.analyze.regress(module_feature_object, dose_dict, method='LinearRegression', degree=1, alpha=1)[source]
Regress a continuous variable (e.g., dose, stimulus value) from a module or keypoint feature object
- Parameters:
module_feature_object – ModuleUsage, ModuleTransitions, or KeypointFeature object
dose_dict – dictionary with keys corresponding to subgroups and items corresponding to variable
method – method of regression; either “LinearRegression” (default) or “Ridge” or “Lasso”
degree – polynomial degree; default 1
alpha – alpha (default 1; only applies for regularized regression, i.e. Ridge and Lasso)
- Returns:
regression model, dose_labels