Skip to content

Conversation

@skoghoern
Copy link
Contributor

I stumbled upon this small edge case during inference. check if you think it is helpful, inference also worked without it, but i thought it might add more stability.

Description

when the incoming messages ($q_{\text{out}}$ and $q_{\mu}$) are identical point masses, the invS became a singularity, zero matrix, leading to an undefined Wishart distribution.
To prevent this, this PR introduces a small regularization term ($\epsilon \mathbf{I}$) to the calculation of the inverse scale matrix ($\mathbf{invS}$) in the $\mathbf{\Lambda}$ VMP update.

Changes

The invS calculation now adds $10^{-6}$ times the identity matrix ($\mathbf{I}$) for robustness.

invS_raw = v_mean + v_out + (m_mean - m_out) * (m_mean - m_out)'
invS = invS_raw + 1e-6 * diagm(ones(D))

This regularization guarantees $\mathbf{invS}$ is positive definite, ensuring the resulting Wishart distribution for the precision matrix is always proper.

Regularize invS in MvNormalMeanPrecision(:Λ, Marginalisation) rule to prevent singularity
Regularize invS in MvNormalMeanPrecision(:Λ, Marginalisation) rule to prevent singularity
deleted space
@bvdmitri
Copy link
Member

bvdmitri commented Oct 30, 2025

I think its a very nice change! But I would rather use our MatrixCorrectionTools library for this purpose. Look at the example here. The idea here is that you can use the meta to allow for different strategies (e.g. maybe 1e-6 is not enough)

@bvdmitri bvdmitri self-requested a review October 30, 2025 10:40
@skoghoern
Copy link
Contributor Author

thats actually a really cool feature there - thx for highlighting it.
i just adapted it. and also for the joint cluster case µ_out. i guess it could happen there as well.

@bvdmitri
Copy link
Member

bvdmitri commented Nov 4, 2025

Thanks! I started the CI just in case, but I don't think it will break anything

@bvdmitri bvdmitri merged commit d2fd139 into ReactiveBayes:main Nov 5, 2025
6 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