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

Fix deprecation #430

Merged
merged 4 commits into from
Nov 14, 2024
Merged

Fix deprecation #430

merged 4 commits into from
Nov 14, 2024

Conversation

kahaaga
Copy link
Member

@kahaaga kahaaga commented Oct 8, 2024

In #427, I fixed the error disallowing different-type outcome containers for Probabilities. However, that introduced the deprecation warning again. This fixes the resulting deprecations warning.

I fixed the error disallowing different-type outcome containers. However, that introduced the deprecation warning again. This fixes the resulting deprecations warning.
Copy link
Member

@Datseris Datseris left a comment

Choose a reason for hiding this comment

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

Increment patch, merge, and tag, please.

@Datseris
Copy link
Member

Datseris commented Oct 8, 2024

AH NO! Test fail!!!!!!!!

@kahaaga
Copy link
Member Author

kahaaga commented Oct 8, 2024

Test fails are unrelated. Seems like a random tolerance thing related to the sum of probabilities. We can safely merge this without affecting anything else.

Copy link
Member

@Datseris Datseris left a comment

Choose a reason for hiding this comment

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

Test have been restarted 5 times by now but they still fail. I think the failure should be fixed. It isn't even a test failure but an @assert statement failing. It isn't failing on main branch.

if probs don't sum exactly to 1, then we normalize in the last step anyways.
the assert statement did actually catch a mistake that was caused elsewhere, so it should stay in and keep doing its job.
@kahaaga
Copy link
Member Author

kahaaga commented Nov 14, 2024

Test have been restarted 5 times by now but they still fail. I think the failure should be fixed. It isn't even a test failure but an @Assert statement failing. It isn't failing on main branch.

The error occurred because the sums of the counts computed using the CosineSimilarityBinning outcome space didn't match the expected number of outcomes obtained from encoded_space_cardinality (see attached definition below).

The actual counts were missing an observation. The reason is that the cosine similarity is supposed to be bounded on [-1, 1], but sometimes, due to imprecision errors, it sometimes got a value of 1.00000000...2. The FixedRectangularBinning used to encode the cosine similarity distances is defined on [-1, 1 + eps()). But this didn't catch these points that fall juuuust outside the right-hand range of the binning. I fixed it by restricting the computed cosine similarity value to 1-eps().

Note: another alternative would be to use the precise argument to the FixedRectangularBinning, but that would make binning four times slower, so I opted for just adjusting the value of the cosine similarity so that it is within the bin edges.

Why this suddenly occurs I have not been able to track down. My best guess is that it has something to do with random number generation during testing.

Anyways: it is fixed now, so I'm merging and tagging.

relevant code

function probs_and_outs_from_histogram(est::AddConstant, outcomemodel::OutcomeSpace,
        cts::Counts{T, 1}, outs, x) where T

    c = est.c
    m = length(cts)
    n = encoded_space_cardinality(outcomemodel, x) # Normalize based on *encoded* data.
    probs = zeros(m)
    for (k, nₖ) in enumerate(cts)
        probs[k] = (nₖ + c) / (n + (c * m))
    end
    @assert sum(probs)  1
    
    return Probabilities(probs, outs,)
end

@kahaaga kahaaga merged commit 87f97d6 into main Nov 14, 2024
2 checks passed
@kahaaga kahaaga deleted the finally_fix_deprecation_error branch November 14, 2024 12:10
@Datseris
Copy link
Member

thanks!

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