glhmm.io¶
Input/output functions - Gaussian Linear Hidden Markov Model @author: Diego Vidaurre 2023
- glhmm.io.get_sorted_filepaths(folder, suffix='.npy')[source]¶
Return file paths in a folder sorted by the trailing numeric index.
- Parameters:
folder (str or Path) – Directory to search.
suffix (str, optional) – File extension to match (default
'.npy').
- Returns:
Sorted list of matching paths.
- Return type:
list of Path
- glhmm.io.load_files(files, I=None, do_only_indices=False)[source]¶
Loads data from files and returns the loaded data, indices, and individual indices for each file.
- glhmm.io.load_hmm(filename, directory=None)[source]¶
Load a glhmm object from the specified file.
Parameters:¶
- filename (str):
Name of the file containing the glhmm object.
- directory (str, optional), default=None:
Directory where the file is located. If None, searches in the current working directory.
Returns:¶
- glhmmobject
Loaded glhmm object.
- glhmm.io.load_statistics(filename, directory=None)[source]¶
Load statistics data from a file.
- Parameters:
filename (str) – The name of the file containing the saved statistics data, with or without extension.
(str (load_directory) – The directory path where the file is located (default is the current working directory).
optional) – The directory path where the file is located (default is the current working directory).
default=None – The directory path where the file is located (default is the current working directory).
- Returns:
data_dict – The dictionary containing the loaded statistics data.
- Return type:
dict
- glhmm.io.read_flattened_hmm_mat(file)[source]¶
Reads a MATLAB file containing hidden Markov model (HMM) parameters from the HMM-MAR toolbox, and initializes a Gaussian linear hidden Markov model (GLHMM) using those parameters.
- glhmm.io.save_concatenated_subjects(X_clean, output_dir, prefix='subject', overwrite=False)[source]¶
Save one .npy file per subject from a list of session arrays.
- Parameters:
X_clean (list of lists of ndarray) – Outer list: subjects. Inner list: sessions. Each element has shape (n_timepoints_session, n_features). Sessions are concatenated along axis 0.
output_dir (str or Path) – Directory where per-subject files will be written.
prefix (str, optional) – Filename prefix; files are named
{prefix}_{i:04d}.npy.overwrite (bool, optional) – If False (default), existing files are skipped.
- glhmm.io.save_hmm(hmm, filename, directory=None)[source]¶
Save a glhmm object in the specified directory with the given filename.
Parameters:¶
- hmm (object)
The glhmm object to be saved.
- filename (str)
The name of the file to which the object will be saved.
- directory (str, optional), default=None:
The directory where the file will be saved. If None, saves in the current working directory.
- glhmm.io.save_statistics(data_dict, filename='statistics', directory=None, format='npy')[source]¶
Save statistics data to a file in the specified directory with optional format (npy or npz).
- Parameters:
(dict) (data_dict) – Dictionary containing statistics data to be saved.
(str (format) – Name of the file.
optional) – Name of the file.
default='statistics' – Name of the file.
(str – Directory path where the file will be saved (default is the current working directory).
optional) – Directory path where the file will be saved (default is the current working directory).
default=None – Directory path where the file will be saved (default is the current working directory).
(str – Serialization format (‘npy’ or ‘npz’).
optional) – Serialization format (‘npy’ or ‘npz’).
default='npy' – Serialization format (‘npy’ or ‘npz’).
- glhmm.io.save_subjects_file(X_clean, output_dir, prefix='subject', overwrite=False)[source]¶
Save one .npy file per subject from a 3-D array.
- Parameters:
X_clean (ndarray, shape (n_timepoints, n_subjects, n_features)) – Brain data with all subjects stacked along axis 1.
output_dir (str or Path) – Directory where per-subject files will be written.
prefix (str, optional) – Filename prefix; files are named
{prefix}_{i:04d}.npy.overwrite (bool, optional) – If False (default), existing files are skipped.