Utils Module¶
- visualize_training.utils.break_list_by_lengths(lst, lengths)¶
Break the list in chunks of specified length
- Parameters:
lst (list) – input list
lengths (int) – lengh of one chunk
- Returns:
list of chunks of specified length
- Return type:
result
- visualize_training.utils.characterize_all_transitions(model, data, best_predictions, cols, lengths, phases, top_n)¶
Characterize phase transitions for all the phase permutations.
- Parameters:
model – HMM model object
data (list) – List of dataframes used to train HMM model.
best_predictions (list) – List of list of predictions broken into respective lengths of dataframes.
lengths (list) – List of lengths of dataframes.
cols (list) – List of columns to be returned in sorted order
phases (_type_) – _description_
top_n (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
- visualize_training.utils.characterize_transition_between_phases(model, data, best_predictions, cols, lengths, i, j)¶
Compute the average derivative for each feature, sort features by highest absolute value
- Parameters:
model – HMM model object
data (list) – List of dataframes used to train HMM model.
best_predictions (list) – List of list of predictions broken into respective lengths of dataframes.
lengths (list) – List of lengths of dataframes.
cols (list) – List of columns to be returned in sorted order
i (str) – Initial phase from where the transition is originating.
j (str) – Final phase where the transition is reaching.
- visualize_training.utils.find_i_followed_by_j(lst, i, j)¶
Find transition in the estimated hidden state
- Returns:
indexes of predictions where i is followed by j
- Return type:
indexes
- visualize_training.utils.get_derivatives(X, model)¶
Compute the derivative d/dz_t p(s_t = k | z_{1:t}) for the entire forward lattice.
- Parameters:
X (dataframe) – Data used to train HMM model
model – HMM model object
- Returns:
derivates (list)
- visualize_training.utils.get_difference_bt_means(model, phase_1, phase_2)¶
Returns the difference between mean values of two different phases
- Parameters:
model – Trained HMM Model
phase_1 (int) – Source Phase of a transition
phase_2 (int) – Destination phase of a transition
- visualize_training.utils.get_features_for_transition(model, data, best_predictions, lengths, phase_1, phase_2)¶
Return Top N features responsible for a state transition.
For each time a transition (phase_1 -> phase_2) happens, compute the derivatives for each feature.
This computation is slightly inefficient, in that it computes the entire forward lattice of derivatives.
In practice, this inefficiency doesn’t seem to be an issue in terms of runtime.
- Parameters:
model – HMM Model object
data (list) – List of dataframes used to train HMM model.
best_predictions (list) – List of list of predictions broken into respective lengths of dataframes.
lengths (list) – List of lengths of dataframes.
phase_1 (str) – Initial phase from where the transition is originating.
phase_2 (str) – Final phase where the transition is reaching.
- Returns:
_description_
- Return type:
_type_
- visualize_training.utils.load_model(model_path)¶
Load trained HMM model from directory
- Parameters:
model_path (str) – Path to the directory of the model
- Returns:
HMM Model object
- visualize_training.utils.make_hmm_data(data_dir, cols, sort=True, first_n=1000, sort_col='epoch')¶
Data Preprocessing method similar to the one present in HMM class. Separate method intended to be used independently on need basis.
- Parameters:
data_dir (str) – Path to data files.
cols (list) – List of columns to be returned.
sort (bool) – Whether to sort the rows based on sort_col or not. Defaults to True.
first_n (int) – No of rows to be returned for each data file. Defaults to 1000.
sort_col (str) – Column name based on which sorting needs to be done. Defaults to “epoch”
- Returns:
List of dataframes for training the HMM test_dfs (list): List of dataframes for testing the HMM train_data (array): All the dataframes in train_dfs stacked vertically test_data (array): All the dataframes in test_dfs stacked vertically
- Return type:
train_dfs (list)
- visualize_training.utils.save_model(model_path, model)¶
Saves trained HMM model to directory
- Parameters:
model_path (str) – Directory path where model needs to be saved.
model – Trained Model object.
- visualize_training.utils.softmax_with_overflow(logits)¶
log-sum-exp. convert logits into probabilities using softmax