-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user to choose between safe/unsafe/fastcholesky inverse in Gaussian nodes #76
Comments
I am not sure whether this should be a flag for Gaussian nodes. I think it is better to always constrain the This issue might be better formulated whether we wish to constrain covariance/precision matrices to always be Hermitian. I am not sure whether we have cases when this does not apply. |
Agree with @bartvanerp that However, we can easily encounter situations when the pos-def property is violated.
Assuming Another 'easy to spot' example is from the rule itself: @rule typeof(*)(:out, Marginalisation) (m_A::PointMass{ <: AbstractVector }, m_in::UnivariateNormalDistributionsFamily) = begin
a = mean(m_A)
μ_in, v_in = mean_var(m_in)
# TODO: check, do we need correction! here? (ForneyLab does not have any correction in this case)
# TODO: Σ in this rule is guaranteed to be ill-defined, has rank equal to one and has determinant equal to zero
μ = μ_in * a
Σ = mul_inplace!(v_in, a * a')
return MvNormalMeanCovariance(μ, Σ)
end You are almost always guaranteed to end up with a non-Hermitian "covariance" matrix in this case. |
I agree that sometimes we end up with improper distributions, from which the covariance/precision matrix is not positive definite. However, this does not mean that the matrix is not Hermitian I believe. Maybe I am wrong here, but the cholesky function just assumes that the covariance/precision matrix can be represented by just its lower/upper triangular matrix. What happens in #69 is the following:
|
@bartvanerp the problem here is that This issue came up from our conversion with Albert. There are some matrices that do have a proper inverse, but they are neither symmetrical nor Hermitian. In some situation (IMO rare, but anyway) user might prefer to use a different inverse method if they now the structure of their improper covariance matrix. E.g.
I do think though that having such an inverse for lets say covariance matrix might make little sense from mathematical point of view. As a workaround a user can always define such methods with the |
I am not sure whether I am following entirely here, so better to discuss this in person.
So then we just use
What do you mean with improper here? If we are dealing with an arbitrary non-symmetric covariance/precision matrix then we can make it symmetric by just redistributing its elements without any loss of generality. Then we can call julia> B = [1.0 0.5; 0.5 1]
2×2 Matrix{Float64}:
1.0 0.5
0.5 1.0
julia> ReactiveMP.cholinv(B) * B
2×2 Matrix{Float64}:
1.0 -1.11022e-16
0.0 1.0 |
Yes and yes. But neither of these options can be controlled by a user in message update rules. In message update rules we always use |
We recently discussed an associated issue, with julia> fastcholesky([ 0.0 0.0; 0.0 0.0 ])
LinearAlgebra.Cholesky{Float64, Matrix{Float64}}
L factor:
2×2 LinearAlgebra.LowerTriangular{Float64, Matrix{Float64}}:
1.0 ⋅
0.0 1.0 The remedy would be to assume that any matrix that is passed to the Gaussian is proper. For non-proper non-invertible matrices we must implement a special type of matrix, e.g. |
This might be a meta flag for Gaussian nodes.
For example by default we might assume Hermittian structure and use
meta = AssumeHermittian()
that fallbacks tofastcholesky
.In other cases we might prever
pinv()
, e.g.meta = AssumeNonHermittian()
@bartvanerp , @albertpod
The text was updated successfully, but these errors were encountered: