Borrow some ideas from GetDist Python package

Open
#92 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
julia
Domain
data

Research direction

The issue names no repository files or tests. Start by reproducing the linked comparison with KernelDensity.jl, the GetDist Python package, and the cited paper; the requested implementation and completion criteria still need to be defined.

Written by the indexing model from the issue text.

Description

Generally I find the GetDist Python package based on this paper does a much better job producing accurate contours than this one, in particular for close-to-Gaussian distributions and especialy with boundaries. E.g. here's a comparison for 100 samples from a unit normal distribution (top row) or a unit normal truncated below 0 (bottom row; code at the end of this post):

image

image

I don't know if there's any motivation here from anyone to borrow / implement some ideas from that paper, but I figured I'd put it out there, it would be very nice to have a pure-Julia version.

using PyCall, PyPlot, KernelDensityEstimate, KernelDensity, Distributions, Random
getdist = pyimport("getdist")
getdist.chains.print_load_details = false;

## no boundary

Random.seed!(0)
samples = randn(100);

xs = range(-4,4,length=100);
figure(figsize=(10,4))

ax = nothing

for (i,(label, Pxs)) in enumerate([
    ("KernelDensity.jl",         KernelDensity.pdf(KernelDensity.kde(samples), xs)),
    ("KernelDensityEstimate.jl", KernelDensityEstimate.evaluateDualTree(KernelDensityEstimate.kde!(samples), xs)),
    ("GetDist.py",               getdist.MCSamples(;samples, weights=nothing, names=["x"]).get1DDensity(0).normalize("integral")(xs))
])

    ax = subplot(1,3,i, sharex=ax, sharey=ax)
    plot(xs, pdf.(Normal(), xs),c="k", ls="--", alpha=0.6, label="truth")
    hist(samples, color="k", alpha=0.2, density=true)
    plot(xs, Pxs)
    title(label)

end

## with boundary

Random.seed!(0)
samples = filter(>(0), randn(200))

xs = range(-4,4,length=100)
figure(figsize=(10,4))

ax = nothing

for (i,(label, Pxs)) in enumerate([
    ("KernelDensity.jl",         KernelDensity.pdf(KernelDensity.kde(samples, boundary=(0,10)), xs)),
    ("KernelDensityEstimate.jl", KernelDensityEstimate.evaluateDualTree(KernelDensityEstimate.kde!(samples), xs)),
    ("GetDist.py",               getdist.MCSamples(;samples, weights=nothing, names=["x"], ranges=Dict("x"=>(0,nothing))).get1DDensity(0).normalize("integral")(xs))
])

    ax = subplot(1,3,i, sharex=ax, sharey=ax)
    plot(xs, pdf.(TruncatedNormal(0,1,0,Inf), xs),c="k", ls="--", alpha=0.4, label="truth")
    hist(samples, color="k", alpha=0.2, density=true)
    plot(xs, Pxs)
    title(label)

end
Dominant language
Julia
Stars
213
Forks
45
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaStats/KernelDensity.jl

All issues in JuliaStats/KernelDensity.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.