From f1ac9988333570551c91304a5225cd2d1ea77206 Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:25:52 -0400 Subject: [PATCH 1/9] Add dependabot.yml --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..ff6499d6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "weekly" \ No newline at end of file From 67d0fb4cb8b02d71e0bb098ac6d8ada96a02e0d5 Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:26:58 -0400 Subject: [PATCH 2/9] Separate docs workflow into separate file --- .github/workflows/CI.yml | 32 ++++---------------------------- .github/workflows/docs.yml | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 8339b0f1..e60584ae 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,11 +1,9 @@ name: CI on: pull_request: - branches: - - master + branches: [master] push: - branches: - - master + branches: [master] tags: '*' jobs: test: @@ -23,7 +21,7 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@latest with: version: ${{ matrix.version }} @@ -34,26 +32,4 @@ jobs: - uses: julia-actions/julia-processcoverage@latest - uses: codecov/codecov-action@v3 with: - file: lcov.info -# docs: -# name: Documentation -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v2 -# - uses: julia-actions/setup-julia@v1 -# with: -# version: '1' -# - run: | -# julia --project=docs -e ' -# using Pkg -# Pkg.develop(PackageSpec(path=pwd())) -# Pkg.instantiate()' -# - run: | -# julia --project=docs -e ' -# using Documenter: doctest -# using MYPACKAGE -# doctest(MYPACKAGE)' # change MYPACKAGE to the name of your package -# - run: julia --project=docs docs/make.jl -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} + file: lcov.info \ No newline at end of file diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..66b98223 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,30 @@ +name: Documentation +on: + pull_request: + branches: [master] + push: + branches: [master] + tags: '*' +jobs: +# docs: +# name: Build Documentation +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v2 +# - uses: julia-actions/setup-julia@v1 +# with: +# version: '1' +# - run: | +# julia --project=docs -e ' +# using Pkg +# Pkg.develop(PackageSpec(path=pwd())) +# Pkg.instantiate()' +# - run: | +# julia --project=docs -e ' +# using Documenter: doctest +# using MYPACKAGE +# doctest(MYPACKAGE)' # change MYPACKAGE to the name of your package +# - run: julia --project=docs docs/make.jl +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} \ No newline at end of file From 78c7ae8bab345300c5c23adc5dc8403690e718da Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:28:41 -0400 Subject: [PATCH 3/9] Add docs env --- docs/Project.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/Project.toml diff --git a/docs/Project.toml b/docs/Project.toml new file mode 100644 index 00000000..f45c5bdc --- /dev/null +++ b/docs/Project.toml @@ -0,0 +1,6 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b" + +[sources.KernelDensity] +path = ".." From 9189eea27729dc5eb46766753878222908b212c4 Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:32:34 -0400 Subject: [PATCH 4/9] Ignore docs build files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ae3a70e3..f0fe1401 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ examples/.ipynb_checkpoints/* -Manifest.toml \ No newline at end of file +Manifest.toml +docs/build/ \ No newline at end of file From c91935a9bff2f297465d0c8459f9837cf8b82c74 Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:38:54 -0400 Subject: [PATCH 5/9] Create docs folder structure --- docs/make.jl | 10 +++++ docs/src/index.md | 108 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 docs/make.jl create mode 100644 docs/src/index.md diff --git a/docs/make.jl b/docs/make.jl new file mode 100644 index 00000000..32d9e189 --- /dev/null +++ b/docs/make.jl @@ -0,0 +1,10 @@ +using Documenter +using KernelDensity + +makedocs( + sitename = "KernelDensity.jl", + modules = [KernelDensity], +) +deploydocs( + repo = "github.com/JuliaStats/KernelDensity.jl.git", +) \ No newline at end of file diff --git a/docs/src/index.md b/docs/src/index.md new file mode 100644 index 00000000..abc2406d --- /dev/null +++ b/docs/src/index.md @@ -0,0 +1,108 @@ +```@meta +CurrentModule = KernelDensity +``` + +# KernelDensity.jl + +Kernel density estimators for Julia. + +## Usage + +### Univariate +The main accessor function is `kde`: + +```julia +U = kde(data) +``` + +will construct a `UnivariateKDE` object from the real vector `data`. The +optional keyword arguments are +* `boundary`: the lower and upper limits of the kde as a tuple. Due to the + fourier transforms used internally, there should be sufficient spacing to + prevent wrap-around at the boundaries. +* `npoints`: the number of interpolation points to use. The function uses + fast Fourier transforms (FFTs) internally, so for optimal efficiency this + should be a power of 2 (default = 2048). +* `kernel`: the distributional family from + [Distributions.jl](https://github.com/JuliaStats/Distributions.jl) to use as + the kernel (default = `Normal`). To add your own kernel, extend the internal + `kernel_dist` function. +* `bandwidth`: the bandwidth of the kernel. Default is to use Silverman's + rule. + +The `UnivariateKDE` object `U` contains gridded coordinates (`U.x`) and the density +estimate (`U.density`). These are typically sufficient for plotting. +A related function + +``` kde_lscv(data) ``` + +will construct a `UnivariateKDE` object, with the bandwidth selected by +least-squares cross validation. It accepts the above keyword arguments, except +`bandwidth`. + + +There are also some slightly more advanced interfaces: +```julia +kde(data, midpoints::R) where R<:AbstractRange +``` +allows specifying the internal grid to use. Optional keyword arguments are +`kernel` and `bandwidth`. + +```julia +kde(data, dist::Distribution) +``` +allows specifying the exact distribution to use as the kernel. Optional +keyword arguments are `boundary` and `npoints`. + +```julia +kde(data, midpoints::R, dist::Distribution) where R<:AbstractRange +``` +allows specifying both the distribution and grid. + +### Bivariate + +The usage mirrors that of the univariate case, except that `data` is now +either a tuple of vectors +```julia +B = kde((xdata, ydata)) +``` +or a matrix with two columns +```julia +B = kde(datamatrix) +``` +Similarly, the optional arguments all now take tuple arguments: +e.g. `boundary` now takes a tuple of tuples `((xlo,xhi),(ylo,yhi))`. + +The `BivariateKDE` object `B` contains gridded coordinates (`B.x` and `B.y`) and the bivariate density +estimate (`B.density`). + +### Interpolation + +The KDE objects are stored as gridded density values, with attached +coordinates. These are typically sufficient for plotting (see above), but +intermediate values can be interpolated using the +[Interpolations.jl](https://github.com/tlycken/Interpolations.jl) package via the `pdf` method +(extended from Distributions.jl). + +```julia +pdf(k::UnivariateKDE, x) +pdf(k::BivariateKDE, x, y) +``` + +where `x` and `y` are real numbers or arrays. + +If you are making multiple calls to `pdf`, it will be more efficient to +construct an intermediate `InterpKDE` to store the interpolation structure: + +```julia +ik = InterpKDE(k) +pdf(ik, x) +``` + +`InterpKDE` will pass any extra arguments to `interpolate`. + +## API Reference + +```@autodocs +Modules = [KernelDensity] +``` \ No newline at end of file From e06a1c6be6eb0b47ba41b0162f7d943934e84e82 Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:39:02 -0400 Subject: [PATCH 6/9] Activate docs workflow --- .github/workflows/docs.yml | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 66b98223..9d38a958 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -6,25 +6,15 @@ on: branches: [master] tags: '*' jobs: -# docs: -# name: Build Documentation -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v2 -# - uses: julia-actions/setup-julia@v1 -# with: -# version: '1' -# - run: | -# julia --project=docs -e ' -# using Pkg -# Pkg.develop(PackageSpec(path=pwd())) -# Pkg.instantiate()' -# - run: | -# julia --project=docs -e ' -# using Documenter: doctest -# using MYPACKAGE -# doctest(MYPACKAGE)' # change MYPACKAGE to the name of your package -# - run: julia --project=docs docs/make.jl -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} \ No newline at end of file + documenter: + name: Build Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: '1' + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-docdeploy@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 417ae2f216679bbfe7c5aa548f63e96fb467b174 Mon Sep 17 00:00:00 2001 From: Abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:40:15 -0400 Subject: [PATCH 7/9] Update codecov action version --- .github/workflows/CI.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e60584ae..3fae3229 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -30,6 +30,7 @@ jobs: - uses: julia-actions/julia-buildpkg@latest - uses: julia-actions/julia-runtest@latest - uses: julia-actions/julia-processcoverage@latest - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v5 with: - file: lcov.info \ No newline at end of file + files: lcov.info + token: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file From 92f5068af7024c18fa10234ef1794b87fa909233 Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:44:03 -0400 Subject: [PATCH 8/9] Add compat for Documenter.jl --- docs/Project.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index f45c5bdc..4fa26b93 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -2,5 +2,8 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b" +[compat] +Documenter = "1" + [sources.KernelDensity] path = ".." From c4387a12ebef4ab2a3db8217b5dd6bbf69484ab8 Mon Sep 17 00:00:00 2001 From: abhro <5664668+abhro@users.noreply.github.com> Date: Wed, 12 Mar 2025 11:47:56 -0400 Subject: [PATCH 9/9] Allow docs push preview (for PRs) --- docs/make.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/make.jl b/docs/make.jl index 32d9e189..f514f5b2 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -7,4 +7,5 @@ makedocs( ) deploydocs( repo = "github.com/JuliaStats/KernelDensity.jl.git", -) \ No newline at end of file + push_preview = true, +)