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

wand bins patch: fix #479 #480

Merged
merged 9 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ uuid = "f3b207a7-027a-5e70-b257-86293d7955fd"
version = "0.14.30"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Clustering = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DataValues = "e7dc6d0d-1eca-5fa6-8ad6-5aecde8b7ea5"
Expand Down
2 changes: 1 addition & 1 deletion src/StatsPlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Clustering: Hclust, nnodes
using Interpolations
import MultivariateStats: MDS, eigvals, projection, principalvars,
principalratio, transform

import AbstractFFTs: fft, ifft
mkborregaard marked this conversation as resolved.
Show resolved Hide resolved
import KernelDensity
@recipe f(k::KernelDensity.UnivariateKDE) = k.x, k.density
@recipe f(k::KernelDensity.BivariateKDE) = k.x, k.y, permutedims(k.density)
Expand Down
6 changes: 3 additions & 3 deletions src/hist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ function bkfe(gcounts, drv, bandwidth, range_x)
## Obtain kernel weights

tau = 4 + drv
L = min(floor(tau*h/delta), M)
L = min(floor(Int, tau*h/delta), M)
mkborregaard marked this conversation as resolved.
Show resolved Hide resolved

lvec = 0:L
arg = lvec .* delta/h

kappam = pdf(Normal(),arg)/(h^(drv+1))
kappam = pdf.(Normal(),arg)/(h^(drv+1))
mkborregaard marked this conversation as resolved.
Show resolved Hide resolved
hmold0, hmnew = ones(length(arg)), ones(length(arg))
hmold1 = arg

Expand All @@ -227,7 +227,7 @@ function bkfe(gcounts, drv, bandwidth, range_x)

## Now combine weights and counts to obtain estimate
## we need P >= 2L+1L, M: L <= M.
P = 2^(ceil(log(M+L+1)/log(2)))
P = 2^(ceil(Int, log(M+L+1)/log(2)))
mkborregaard marked this conversation as resolved.
Show resolved Hide resolved
kappam = [kappam; zeros(P-2*L-1); reverse(kappam[2:end])]
Gcounts = [gcounts; zeros(P-M)]
kappam = fft(kappam)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ end # testset
]
end

@testset "Histogram" begin
data = randn(1000)
@test 0.3 < StatsPlots.wand_bins(data) < 0.4
end

@testset "Distributions" begin
@testset "univariate" begin
@testset "discrete" begin
Expand Down