moseq2_model.helpers Package

Helpers - Data Module

Helper functions for reading data from index files, and preparing metadata prior to training.

moseq2_model.helpers.data.get_heldout_data_splits(data_dict, train_list, hold_out_list)

Split data by session UUIDs into training and held out datasets.

Args: data_dict (OrderedDict): dictionary of all PC scores included in the model train_list (list): list of keys included in the training data hold_out_list (list): list of keys included in the held out data

Returns: train_data (OrderedDict): dictionary of uuid to PC score key-value pairs for uuids in train_list test_data (OrderedDict): dictionary of uuids to PC score key-value pairs for uuids in hold_out_list.

moseq2_model.helpers.data.get_training_data_splits(split_frac, data_dict)

Split the data into a training and held out dataset by splitting each session by some fraction percent_split.

Args: split_frac (float): fraction to split each session into training data, leaving the rest as validation data. data_dict (OrderedDict): dict of uuid-PC Score key-value pairs for all data included in the model.

Returns: training_data (OrderedDict): the split percentage of the training data. validation_data (OrderedDict): the split percentage of the validation data

moseq2_model.helpers.data.graph_modeling_loglikelihoods(config_data, iter_lls, iter_holls, model_dir)

Graph model training performance progress throughout modeling if verbose is True

Args: config_data (dict): dictionary of model training parameters. iter_lls (list): list of training log-likelihoods for each training iteration iter_holls (list): list of held out log-likelihoods for each training iteration model_dir (str): path to the directory the model is saved in.

Returns: img_path (str): path to saved graph.

moseq2_model.helpers.data.prepare_model_metadata(data_dict, data_metadata, config_data)

Set model training metadata parameters, whiten data, split data and return list of heldout keys if applicable, and update all dictionaries.

Args: data_dict (OrderedDict): loaded data dictionary. data_metadata (OrderedDict): loaded metadata dictionary. config_data (dict): dictionary containing all modeling parameters.

Returns: data_dict (OrderedDict): optionally whitened and updated data dictionary. model_parameters (dict): model parameters used to initialize the ARHMM train_list (list): list of session uuids to include for training. hold_out_list (list): list of session uuids to hold out (if hold_out == True)

moseq2_model.helpers.data.process_indexfile(index, data_metadata, default_group='n/a', select_groups=False)

Read index file (if applicable) and return dictionaries containing metadata in the index file.

Args: index (str or None): path to index file. data_metadata (dict): loaded metadata containing uuid and group information. default_group (str): default group name to supply to data without assigned group labels select_groups (bool): when True, print metadata describing group selection

Returns: index_data (dict): loaded index file. data_metadata (dict): updated metadata dictionary.

moseq2_model.helpers.data.select_data_to_model(index_data, data_dict, data_metadata, select_groups=False)

Select the data to model.

Args: index_data (dict): loaded dictionary from index file data_dict (dict): dictionary containing PC scores for all sessions data_metadata (dict): dictionary containing metadata associated with the recording sessions select_groups (bool): flag to solicit user input on which groups to select for modeling

Returns: data_dict (dict): dictionary to model containing data from the selected session uuids data_metadata (dict): updated metadata containing the selected uuids and groups

Helpers - Wrappers Module

Wrapper functions for CLI and GUI.

moseq2_model.helpers.wrappers.apply_model_wrapper(model_file, pc_file, dest_file, config_data)

Wrapper function to apply a pre-trained model to new data.

Args: model_file (str): Path to pre-trained model file pc_file (str): Path to PC scores file dest_file (str): Path to save output file

Returns: None

moseq2_model.helpers.wrappers.kappa_scan_fit_models_wrapper(input_file, config_data, output_dir)

Wrapper function to output multiple model training commands for a range of kappa values.

Args: input_file (str): Path to PC Scores config_data (dict): Dictionary containing model training parameters output_dir (str): Path to output directory to save trained models

Returns: command_string (str): CLI command string for model training commands.

moseq2_model.helpers.wrappers.learn_model_wrapper(input_file, dest_file, config_data)

Wrapper function to train ARHMM on PC scores.

Args: input_file (str): path to pc scores file. dest_file (str): path to save model to. config_data (dict): dictionary containing the modeling parameters.

Returns: None