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

Add univariate KDE #13

Closed
wants to merge 13 commits into from
Closed

Add univariate KDE #13

wants to merge 13 commits into from

Conversation

sethaxen
Copy link
Member

@sethaxen sethaxen commented Aug 14, 2023

This PR implements univariate KDE, following #6, as well as a cumulative variant.

It tries to make as few modifications to KernelDensity as possible, in the hopes of upstreaming this code to KernelDensity. Its extra functionality is limited to:

  1. padding the density bounds for convolution by n histogram bins, where n is chosen such that the probability mass in the left padding area from convolving the kernel with the rightmost data point is less than 1e-3. This padding is removed, which without boundary correction would produce an unnormalized KDE
  2. performing boundary correction using reflection. We double the padding and reflect the density in the half of the padding closest to the data boundaries, which is equivalent to reflecting the data points to fill the half of the padding closest to the data boundaries. When all padding is removed, this produces a normalized KDE.

It differs from Python arviz primarily in when the boundary correction is performed. Python ArviZ performs it after binning the data into histograms but before convolution. We perform it after convolution.

The two methods are numerically very similar, though the maximum density of this implementation always seems to be a little higher than Python ArviZ's.

tmp

EDIT: removed the cumulative KDE functionality because it's somewhat trivial to get from the KDE and not really recommended, since the ECDF is superior for visualization.

@sethaxen sethaxen changed the title Add univariate KDE Add univariate KDE and cumulative KDE Aug 14, 2023
@sethaxen
Copy link
Member Author

The numerical issues appear to be completely resolved:
tmp

@sethaxen sethaxen changed the title Add univariate KDE and cumulative KDE Add univariate KDE Aug 23, 2023
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Attention: Patch coverage is 0% with 43 lines in your changes missing coverage. Please review.

Project coverage is 92.82%. Comparing base (d4597db) to head (34af628).
Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
src/kde.jl 0.00% 43 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (d4597db) and HEAD (34af628). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (d4597db) HEAD (34af628)
6 3
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
- Coverage   99.82%   92.82%   -7.01%     
==========================================
  Files          11       12       +1     
  Lines         570      613      +43     
==========================================
  Hits          569      569              
- Misses          1       44      +43     

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

@sethaxen sethaxen mentioned this pull request Oct 28, 2024
@sethaxen sethaxen closed this Nov 1, 2024
@sethaxen sethaxen deleted the kde branch November 1, 2024 19:24
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.

1 participant