glhmm.graphics#

Basic graphics - Gaussian Linear Hidden Markov Model @author: Diego Vidaurre 2023

glhmm.graphics.blue_colormap()[source]#
glhmm.graphics.create_cmap_alpha(cmap_list, color_array, alpha)[source]#
glhmm.graphics.custom_colormap()[source]#
glhmm.graphics.interpolate_colormap(cmap_list)[source]#

Create a new colormap with the modified color_array.

Parameters:#

cmap_list (numpy.ndarray): Original color array for the colormap.

Returns:#

modified_cmap (numpy.ndarray): Modified colormap array.

glhmm.graphics.plot_average_probability(Gamma_reconstruct, title='Average probability for each state', fontsize=16, figsize=(7, 5), vertical_lines=None, line_colors=None, highlight_boxes=False)[source]#

Plots the average probability for each state over time.

Parameters:#

Gamma_reconstructnumpy.ndarray

3D array representing reconstructed gamma values. Shape: (num_timepoints, num_trials, num_states)

titlestr, optional

Title for the plot (Default=’Average probability for each state’).

fontsizeint, optional

Font size for labels and title (Default=16).

figsizetuple, optional

Figure size (width, height) in inches (Default=(8, 6)).

vertical_lineslist of tuples, optional

List of pairs specifying indices for vertical lines (Default=None).

line_colorslist of str or bool, optional

List of colors for each pair of vertical lines. If True, generates random colors (unless a list is provided) (Default=None).

highlight_boxesbool, optional

Whether to include highlighted boxes for each pair of vertical lines (Default=False).

Returns:#

None

glhmm.graphics.plot_condition_difference(Gamma_reconstruct, R_trials, title='Average Probability and Difference', fontsize=16, figsize=(9, 2), vertical_lines=None, line_colors=None, highlight_boxes=False)[source]#

Plots the average probability for each state over time for two conditions and their difference.

Parameters:#

Gamma_reconstructnumpy.ndarray

3D array representing reconstructed gamma values. Shape: (num_timepoints, num_trials, num_states)

R_trialsnumpy.ndarray

1D array representing the condition for each trial. Should have the same length as the second dimension of Gamma_reconstruct.

titlestr, optional

Title for the plot (Default=’Average Probability and Difference’).

fontsizeint, optional

Font size for labels and title (Default=16).

figsizetuple, optional

Figure size (width, height) in inches (Default=(9, 2)).

vertical_lineslist of tuples, optional

List of pairs specifying indices for vertical lines (Default=None).

line_colorslist of str or bool, optional

List of colors for each pair of vertical lines. If True, generates random colors (unless a list is provided) (Default= None).

highlight_boxesbool, optional

Whether to include highlighted boxes for each pair of vertical lines (Default=False).

Example usage:#

plot_condition_difference(Gamma_reconstruct, R_trials, vertical_lines=[(10, 100)], highlight_boxes=True)

glhmm.graphics.plot_correlation_matrix(corr_vals, performed_tests, normalize_vals=False, figsize=(9, 5), steps=11, title_text='Heatmap (p-values)', annot=True, cmap_type='default', cmap_reverse=True, xlabel='', ylabel='', xticklabels=None, none_diagonal=False, num_colors=256)[source]#
glhmm.graphics.plot_p_value_matrix(pval, alpha=0.05, normalize_vals=True, figsize=(9, 5), steps=11, title_text='Heatmap (p-values)', annot=True, cmap_type='default', cmap_reverse=True, xlabel='', ylabel='', xticklabels=None, none_diagonal=False, num_colors=259)[source]#
glhmm.graphics.plot_p_values_bar(pval, variables=[], figsize=(9, 4), num_colors=256, xlabel='', ylabel='P-values (Log Scale)', title_text='Bar Plot', tick_positions=[0, 0.001, 0.01, 0.05, 0.1, 0.3, 1], top_adjustment=0.9, alpha=0.05, pad_title=20)[source]#

Visualize a bar plot with LogNorm and a colorbar.

Parameters:#

variables (list): List of categories or variables. pval (array-like): Array of p-values. figsize (tuple, optional): Figure size, default is (9, 4). num_colors (int, optional): Number of colors in the colormap, default is 256. xlabel (str, optional): X-axis label, default is “Categories”. ylabel (str, optional): Y-axis label, default is “Values (log scale)”. title_text (str, optional): Plot title, default is “Bar Plot with LogNorm”. tick_positions (list, optional): Positions of ticks on the colorbar, default is [0, 0.001, 0.01, 0.05, 0.1, 0.3, 1]. top_adjustment (float, optional): Adjustment for extra space between title and plot, default is 0.9.

Returns:#

None

glhmm.graphics.plot_p_values_over_time(pval, figsize=(8, 4), total_time_seconds=None, xlabel='Time points', ylabel='P-values (Log Scale)', title_text='P-values over time', xlim_start=0, tick_positions=[0, 0.001, 0.01, 0.05, 0.1, 0.3, 1], num_colors=259, alpha=0.05, plot_style='line', linewidth=2.5)[source]#

Plot a scatter plot of p-values over time with a log-scale y-axis and a colorbar.

Parameters:#

pvalnumpy.ndarray

The p-values data to be plotted.

total_time_seconds (float, optional):

Total time duration in seconds. If provided, time points will be scaled accordingly.

xlabel (str, optional):

Label for the x-axis. Default is ‘Time points’.

ylabel (str, optional):

Label for the y-axis. Default is ‘Y-axis (log scale)’.

title_text (str, optional):

Title for the plot. Default is ‘P-values over time’.

tick_positions (list, optional):

Specific values to mark on the y-axis. Default is [0, 0.001, 0.01, 0.05, 0.1, 0.3, 1].

num_colors (int, optional):

Resolution for the color bar. Default is 259.

alpha (float, optional):

Alpha value is the threshold we set for the p-values when doing visualization. Default is 0.05.

plot_style (str, optional):

Style of plot. Default is ‘line’.

Returns:#

None (displays the plot).

glhmm.graphics.plot_permutation_distribution(test_statistic, title_text='Permutation Distribution', xlabel='Test Statistic Values', ylabel='Density')[source]#

Plot the histogram of the permutation with the observed statistic marked.

Parameters:#

test_statisticnumpy.ndarray

An array containing the permutation values.

title_textstr, optional

Title text of the plot (Default=”Permutation Distribution”).

xlabelstr, optional

Text of the xlabel (Default=”Test Statistic Values”).

ylabelstr, optional

Text of the ylabel (Default=”Density”).

Returns:#

None

Displays the histogram plot.

glhmm.graphics.plot_scatter_with_labels(p_values, alpha=0.05, title_text='', xlabel=None, ylabel=None, xlim_start=0.9, ylim_start=0)[source]#

Create a scatter plot to visualize p-values with labels indicating significant points.

Parameters:#

p_valuesnumpy.ndarray

An array of p-values. Can be a 1D array or a 2D array with shape (1, 5).

alphafloat, optional

Threshold for significance (Default=0.05).

title_textstr, optional

The title text for the plot (Default=””).

xlabelstr, optional

The label for the x-axis (Default=None).

ylabelstr, optional

The label for the y-axis (Default=None).

xlim_startfloat, optional

Start position of x-axis limits (Default=-5).

ylim_startfloat, optional

Start position of y-axis limits (Default=-0.1).

Returns:#

None

Notes:#

Points with p-values less than alpha are considered significant and marked with red text.

glhmm.graphics.plot_vpath(vpath, signal=[], xlabel='Time Steps', figsize=(7, 4), ylabel='', yticks=None, line_width=2, label_signal='Signal')[source]#
glhmm.graphics.red_colormap()[source]#
glhmm.graphics.show_Gamma(Gamma, line_overlay=None, tlim=None, Hz=1, palette='viridis')[source]#

Displays the activity of the hidden states as a function of time.

Parameters:#

Gammaarray of shape (n_samples, n_states)

The state timeseries probabilities.

line_overlayarray of shape (n_samples, 1)

A secondary related data type to overlay as a line.

tlim2x1 array or None, default=None

The time interval to be displayed. If None (default), displays the entire sequence.

Hzint, default=1

The frequency of the signal, in Hz.

palettestr, default = ‘Oranges’

The name of the color palette to use.

glhmm.graphics.show_beta(hmm, only_active_states=True, recompute_states=False, X=None, Y=None, Gamma=None, show_average=None, alpha=1.0)[source]#

Displays the beta coefficients of a given HMM. The beta coefficients can be extracted directly from the HMM structure or reestimated from the data; for the latter, X, Y and Gamma need to be provided as parameters. This is useful for example if one has run the model on PCA space, but wants to show coefficients in the original space.

Parameters:#

hmm: HMM object

An instance of the HMM class containing the beta coefficients to be visualized.

only_active_states: bool, optional, default=False

If True, only the beta coefficients of active states are shown.

recompute_states: bool, optional, default=False

If True, the betas will be recomputed from the data and the state time courses

X: numpy.ndarray, optional, default=None

The timeseries of set of variables 1.

Y: numpy.ndarray, optional, default=None

The timeseries of set of variables 2.

Gamma: numpy.ndarray, optional, default=None

The state time courses

show_average: bool, optional, default=None

If True, an additional row of the average beta coefficients is shown.

alpha: float, optional, default=0.1

The regularisation parameter to be applied if the betas are to be recomputed.

glhmm.graphics.show_temporal_statistic(Gamma, indices, statistic='FO', type_plot='barplot')[source]#

Plots a statistic over time for a set of sessions.

Parameters:#

Gammaarray of shape (n_samples, n_states)

The state timeseries probabilities.

indices: numpy.ndarray of shape (n_sessions,)

The session indices to plot.

statistic: str, default=’FO’

The statistic to compute and plot. Can be ‘FO’, ‘switching_rate’ or ‘FO_entropy’.

type_plot: str, default=’barplot’

The type of plot to generate. Can be ‘barplot’, ‘boxplot’ or ‘matrix’.

Raises:#

Exception
  • Statistic is not one of ‘FO’, ‘switching_rate’ or ‘FO_entropy’.

  • type_plot is ‘boxplot’ and there are less than 10 sessions.

  • type_plot is ‘matrix’ and there is only one session.

glhmm.graphics.show_trans_prob_mat(hmm, only_active_states=False, show_diag=True, show_colorbar=True)[source]#

Displays the transition probability matrix of a given HMM.

Parameters:#

hmm: HMM object

An instance of the HMM class containing the transition probability matrix to be visualized.

only_active_statesbool, optional, default=False

Whether to display only active states or all states in the matrix.

show_diagbool, optional, defatult=True

Whether to display the diagonal elements of the matrix or not.

show_colorbarbool, optional, default=True

Whether to display the colorbar next to the matrix or not.