Skip to content

Conversation

@bengriffin3
Copy link
Contributor

Summary

This PR adds support for diagonal covariance matrices in the HMM dual estimation pipeline, matching the existing capability in the main HMM model (config.diagonal_covariances). This enables session-specific re-estimation of variance-only observation models, useful for parcellations or analyses where cross-channel covariance structure is not required or not identifiable.

Key changes

  • Extend hmm_dual_estimation (in analysis/post_hoc.py) with a new argument diagonal_covariances=False.
  • Implement efficient diagonal-only covariance estimation (weighted per-channel variances).
  • Ensure returned matrices remain full (n_channels × n_channels) with off-diagonals zeroed.
  • Update hmm_features to:
    • pass through the new option,
    • extract diagonal terms when diagonal_covariances=True,
    • maintain consistency with optional partial correlation transforms.
  • Update Model.dual_estimation to respect config.diagonal_covariances.
  • Update and expand relevant docstrings.

Motivation

Enable dual-estimation workflows where only state-specific variances are needed (e.g., amplitude/power-driven dynamics), consistent with the diagonal-covariance option already available during HMM training. This brings feature parity to post-hoc analysis functions.

Notes

  • Full-covariance behaviour is unchanged.
  • The diagonal option is opt-in and affects only explicit uses.
  • Tested on synthetic data to ensure off-diagonal entries remain zero and behaviour is correct.

@cgohil8 cgohil8 self-assigned this Dec 5, 2025
@cgohil8
Copy link
Collaborator

cgohil8 commented Dec 5, 2025

Nice! Looks good. Maybe one minor comment, can you change the order of the arguments to:

def hmm_dual_estimation(
    data,
    alpha,
    zero_mean=False,
    diagonal_covariances=False,
    eps=1e-5,
    n_jobs=1,
):

@bengriffin3 bengriffin3 force-pushed the feature/hmm-diagonal-dual-estimation branch from 6fe5a27 to 86161a6 Compare December 9, 2025 11:39
@cgohil8 cgohil8 merged commit 07b7dbc into OHBA-analysis:main Dec 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants