-
Notifications
You must be signed in to change notification settings - Fork 0
Better definition of isapprox
#55
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
Conversation
|
copying this here: I'm not sure I'm fully following your derivation, I don't see how you can split the norms like that? But this doesn't behave well with finite precision, since we are basically subtracting equal magnitude numbers to attempt to find something of much smaller magnitude |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #55 +/- ##
==========================================
+ Coverage 81.21% 81.73% +0.52%
==========================================
Files 9 9
Lines 628 646 +18
==========================================
+ Hits 510 528 +18
Misses 118 118
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Good point, I think I missed a few cross terms (I was thinking they would be subleading but I don't think they are). I was trying to circumvent that issue of adding and subtracting large values by first rewriting it in terms of differences |
|
Why not do a similar approach to other parts of the code, and check if |
|
I added in cross terms but also dropped some terms that are second order in the differences julia> using StableRNGs
julia> rng = StableRNG(123);
julia> a = randn(rng, 100, 100) ⊗ randn(rng, 100, 100);
julia> b = (arg1(a) + 1e-1 * randn(rng, size(arg1(a)))) ⊗ (arg2(a) + 1e-1 * randn(rng, size(arg2(a))));
julia> err = norm(collect(a) - collect(b)) / max(norm(a), norm(b))
0.14243654495933608
julia> rtol = 0.143; isapprox(a, b; rtol), isapprox(collect(a), collect(b); rtol)
(false, true)
julia> rtol = 0.1435; isapprox(a, b; rtol), isapprox(collect(a), collect(b); rtol)
(true, true)so it looks like the approximation is pretty good. |
We can definitely do that, some tests rely on the current more general behavior that allows both factors to be different from each other but maybe for those we can just materialize the Kronecker product, I was curious to see if something like this could work that just depends on differences between factors. |
I worked on it a bit more and wrote a more accurate distance function for Kronecker arrays that includes cross terms and second order terms, but even so in the end I agree with you that we should analyze the precision more carefully before using that. I've included that distance function in the package with a test in case we want to use it at some point, but for now I made I rewrote tests that were relying on the less strict behavior of |
Followup to the comments on
isapproxin #54.