Utility functions¶
The utils module provides utilities for handling the data.
Module Reference¶
- encore.utils.data_converters.dict_to_matlab_struct(pars_dict)¶
Converts a Python dictionary to a MATLAB struct.
- Parameters:
pars_dict (dict) – A dictionary where keys represent the names of fields in the MATLAB struct and the values represent the corresponding field values.
- Returns:
A MATLAB struct where the keys are the field names and the values are converted to the appropriate MATLAB data type.
- Return type:
dict
This function recursively converts a Python dictionary to a MATLAB struct. It handles nested dictionaries by recursively calling the conversion function. Numeric values (integers or floats) are converted into MATLAB double type, while other data types are kept unchanged.
- encore.utils.metrics.calculate_neuron_overlap_ratio(m1_neus_in_ens, m2_neus_in_ens)¶
Compute pairwise neuron overlap ratio between two ensemble sets.
- Parameters:
m1_neus_in_ens (numpy.ndarray) – Binary neuron membership for method 1.
m2_neus_in_ens (numpy.ndarray) – Binary neuron membership for method 2.
- Returns:
Overlap ratio matrix.
- Return type:
numpy.ndarray
Compute the number of shared neurons between ensembles from two methods.
- Parameters:
m1_neus_in_ens (numpy.ndarray) – Binary neuron membership for method 1.
m2_neus_in_ens (numpy.ndarray) – Binary neuron membership for method 2.
- Returns:
Matrix of shared neuron counts.
- Return type:
numpy.ndarray
- encore.utils.metrics.compute_auc_roc_ensemble_stimuli(ensemble_timecourse, stimuli)¶
Compute ROC curve and AUC between ensemble activity and stimuli.
- Parameters:
ensemble_timecourse (numpy.ndarray) – Ensemble activity signal.
stimuli (numpy.ndarray) – Binary or continuous stimulus signal.
- Returns:
False positive rate, true positive rate, thresholds, and AUC.
- Return type:
tuple
- encore.utils.metrics.compute_correlation_between_ensembles(ensembles_timecourse)¶
Compute correlation matrix between ensemble timecourses.
- Parameters:
ensembles_timecourse (numpy.ndarray) – Ensemble activity timecourses.
- Returns:
Ensemble-to-ensemble correlation matrix.
- Return type:
numpy.ndarray
- encore.utils.metrics.compute_correlation_inside_ensemble(activity_neus_in_ens)¶
Compute correlation matrix between neurons within an ensemble.
- Parameters:
activity_neus_in_ens (numpy.ndarray) – Neuronal activity matrix.
- Returns:
Neuron-to-neuron correlation matrix.
- Return type:
numpy.ndarray
- encore.utils.metrics.compute_correlation_with_stimuli(ensembles_timecourse, data_stims)¶
Compute Pearson correlations between ensemble timecourses and stimuli.
- Parameters:
ensembles_timecourse (numpy.ndarray) – Ensemble activity array (ensembles, timepoints).
data_stims (numpy.ndarray) – Stimulus timecourses (stimuli, timepoints).
- Returns:
Correlation matrix (ensembles, stimuli).
- Return type:
numpy.ndarray
- encore.utils.metrics.compute_cross_correlations(ensemble_timecourse, stimuli)¶
Compute cross-correlation between ensemble activity and stimuli.
- Parameters:
ensemble_timecourse (numpy.ndarray) – Ensemble activity signal.
stimuli (numpy.ndarray) – Stimulus signal.
- Returns:
Cross-correlation values and corresponding lags.
- Return type:
tuple
- encore.utils.parameters_validators.validate_binary_matrix(matrix: ndarray) bool¶
Validates if a numpy matrix is a binary matrix
- Parameters:
matrix (np.ndarray) – Numpy matrix to validate
- Returns:
Bool value describing if it’s binary
- Return type:
bool
- encore.utils.parameters_validators.validate_params(params: dict, defaults: dict) dict¶
Validate and coerce parameter values based on defaults.
Uses the type of each default value as the expected type
If a parameter is missing or invalid, the default is used
Extra keys in params are ignored
- Parameters:
params – Parameters collected from the GUI
defaults – Default parameter values (type and fallback)
- Returns:
Validated parameter dictionary
- encore.utils.text_formatting.format_nums_to_string(numbers_list)¶
Format a list of numbers into a string, for display purposes.
Every element is separated with a comma, except for the last one.
- Parameters:
numbers_list (list) – List with numbers.
- Returns:
String with the list’s elements separated by a comma.
- Return type:
string