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 Leja ordering for fromroots #586

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

martinholters
Copy link
Contributor

Improve accuracy of fromroots by utilizing Leja ordering, see https://doi.org/10.1023/A:1025555803588 and ref. JuliaDSP/DSP.jl#584.

I'm not sure about code organization and whether this hooks up in all the right places.

Another issue I'm not quite sure about is the correct handling of roots with multiplicity larger than 1.

Finally, this adds substantially to the runtime, but IMHO, accuracy is usually more important than performance here.

@jverzani
Copy link
Member

Thanks! This looks good. I guess a test would be good to catch any regressions.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.01%. Comparing base (b00ea5e) to head (6d698a2).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #586      +/-   ##
==========================================
- Coverage   75.69%   74.01%   -1.69%     
==========================================
  Files          38       38              
  Lines        4040     3817     -223     
==========================================
- Hits         3058     2825     -233     
- Misses        982      992      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@martinholters
Copy link
Contributor Author

I guess a test would be good to catch any regressions.

There is one?

If this looks good otherwise, I'll look into how to (elegantly) work around the missing argmax method on v1.6.

@jverzani
Copy link
Member

It looks good. Thanks again.

...as the required `argmax` method has only been added in Julia v1.7
Comment on lines +988 to +989
if P !== FactoredPolynomial
@test fromroots(P, roots(p)) * p[end] ≈ p
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For FactoredPolynomial, fromroots is trivially correct; the actual conversion happens when promoting to a common type with p. That goes through evalpoly which uses an arbitrary ordering of the roots. I wonder whether it would generally be preferable to use the Leja ordering in evalpoly here, in which case it would probably be worth it to replace the Dict in FactoredPolynomial with an OrderedDict and do the Leja ordering upon construction. No clue whether that's a good idea.

Copy link
Member

Choose a reason for hiding this comment

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

Well that's a question for another day, but it seems like a reasonable thing to do. The extra package has negligible load time.

@martinholters martinholters marked this pull request as ready for review November 13, 2024 08:52
@martinholters
Copy link
Contributor Author

Quite some failing checks, but failures all look unrelated/pre-existing to me.

Comment on lines +24 to +33
#ii = argmax(j -> abs(roots[j]), eachindex(roots))
ii = firstindex(roots)
rmax = abs(roots[ii])
for j in eachindex(roots)
rabs = abs(roots[j])
if rabs > rmax
ii = j
rmax = rabs
end
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.

Alternatively, Compat.jl provides that argmax method. Would depending on Compat be an option or should we keep this loop? (Same below.)

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind having some small copy of package code in this package for easier compatability. I'd keep the loop unless you have a strong preference.

@jverzani
Copy link
Member

Quite some failing checks, but failures all look unrelated/pre-existing to me.

Yes, seems like code coverage changed recently.

@jverzani
Copy link
Member

I'm happy merging now, unless you wanted to adjust the FactoredPolynomial storage. Thanks again!

@martinholters martinholters changed the title RFC: Use Leja ordering for fromroots Use Leja ordering for fromroots Nov 13, 2024
@martinholters
Copy link
Contributor Author

I'm happy merging now, unless you wanted to adjust the FactoredPolynomial storage.

I'm not, merging as is is fine with me. (The other loose end would be the handling of zeros with higher arity where I'm not sure the current implementation follows the paper as I find that part a bit ambiguous. However, even if wrong, that will just be sub-optimal, not a catastrophic failure, and likely still better than what we had before.)

Thanks again!

Welcome!

@martinholters martinholters merged commit d5a472a into JuliaMath:master Nov 13, 2024
14 of 24 checks passed
@martinholters martinholters deleted the mh/leja branch November 13, 2024 16:38
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