Skip to content
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

use Symmetric() to get rid of complex eigen() results #68

Merged
merged 2 commits into from
Nov 18, 2021
Merged

use Symmetric() to get rid of complex eigen() results #68

merged 2 commits into from
Nov 18, 2021

Conversation

aplavin
Copy link
Contributor

@aplavin aplavin commented Nov 15, 2021

No description provided.

@codecov
Copy link

codecov bot commented Nov 15, 2021

Codecov Report

Merging #68 (fde53e4) into main (97af0fe) will increase coverage by 0.58%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
+ Coverage   89.98%   90.56%   +0.58%     
==========================================
  Files          12       12              
  Lines         529      530       +1     
==========================================
+ Hits          476      480       +4     
+ Misses         53       50       -3     
Impacted Files Coverage Δ
src/bounds/ellipsoid.jl 85.39% <100.00%> (+0.16%) ⬆️
src/proposals/Proposals.jl 93.82% <0.00%> (+1.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29a7cbe...fde53e4. Read the comment docs.

Comment on lines 23 to 24
axes, axlens = decompose(A)
Ellipsoid(center, A, axes, axlens, _volume(A))
Copy link
Collaborator

@mileslucas mileslucas Nov 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than incorporate this here, what if we wrote

decompose(A::AbstractMatrix) = decompose(Symmetric(A))

function decompose(A::Symmetric)
	E = eigen(A)
	#...
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes most sense to have Ellipsoid.A field to have type of Symmetric: covariance matrices are symmetric anyway. Unfortunately, it doesn't work because inplace broadcasting with Symmetric isn't implemented in julia yet - there are several issues, eg JuliaLang/julia#38056. So for now, in this PR, I put the Symmetric wrapper as "high" in the call stack as possible. Shifting it to the decompose() level is also possible, of course. Would you prefer that variant?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out the mutation issues- I wasn't aware of those. Yes, I prefer to have this at the decompose level, it's not really too different from what you wrote, but I like using the method signatures. If we had a trait system, we could easily switch from decompose(::Symmetric) to something like decompose(::T) where issymmetric(T). FYI, I do have hopes of improving the entire Bounds interface, since each of these bounds is a sample-able (i.e., implement the Distributions.jl API for samplers), which would also make them immutable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, changed.
My point was that it mathematically only makes sense to run decompose with Symmetric matrices, same for the Ellipsoid creation and other related functions. Shouldn't need any traits even potentially, I think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I've noted that in my ideas for the improvements I alluded to.

@mileslucas mileslucas merged commit b6e4381 into TuringLang:main Nov 18, 2021
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