Skip to content

Commit 4c27128

Browse files
committed
removed @benchmark from test
2 parents 89313ed + a8868b6 commit 4c27128

File tree

5 files changed

+65
-21
lines changed

5 files changed

+65
-21
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ClusterDepth"
22
uuid = "c8d8bbfa-f476-4995-adff-2987f04015d1"
33
authors = ["Benedikt V. Ehinger", "Maanik Marathe"]
4-
version = "0.2.4"
4+
version = "0.2.5"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

src/cluster.jl

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ function clusterdepth(
2626
rng,
2727
data::AbstractArray;
2828
τ=2.3,
29-
stat_type = :onesample_ttest,
30-
perm_type = :sign,
31-
side_type = :abs,
32-
nperm = 5000,
33-
pval_type = :troendle,
34-
(statfun!) = nothing,
35-
statfun = nothing,
36-
permfun = nothing,
29+
stat_type=:onesample_ttest,
30+
perm_type=:sign,
31+
side_type=:abs,
32+
nperm=5000,
33+
pval_type=:troendle,
34+
(statfun!)=nothing,
35+
statfun=nothing,
36+
permfun=nothing,
3737
)
3838
if stat_type == :onesample_ttest && isnothing(statfun!) && isnothing(statfun)
3939
statfun! = studentt!
4040
statfun = studentt
4141
end
4242
if perm_type == :sign
43-
if isnothing(permfun)
44-
permfun = sign_permute!
45-
end
43+
if isnothing(permfun)
44+
permfun = sign_permute!
45+
end
4646
end
4747
if side_type == :abs
4848
sidefun = abs
@@ -51,11 +51,15 @@ function clusterdepth(
5151
elseif side_type == :negative
5252
sidefun = x -> -x
5353
elseif side_type == :positive
54-
sidefun = nothing # the default :)
54+
sidefun = x -> x # the default :)
5555
else
5656
@assert isnothing(side_type) "unknown side_type ($side_type) specified. Check your spelling and ?clusterdepth"
5757
end
58+
data_obs = sidefun.(statfun(data))
5859

60+
if any(data_obs[:, 1] .> τ) || any(data_obs[:, end] .> τ)
61+
@warn "Your data shows a cluster that starts before the first sample, or ends after the last sample. There exists a fundamental limit in the ClusterDepth method, that the clusterdepth for such a cluster cannot be determined. Maybe you can extend the epoch to include more samples?"
62+
end
5963
cdmTuple = perm_clusterdepths_both(
6064
rng,
6165
data,
@@ -67,7 +71,7 @@ function clusterdepth(
6771
sidefun=sidefun,
6872
)
6973

70-
return pvals(statfun(data), cdmTuple, τ; type=pval_type)
74+
return pvals(data_obs, cdmTuple, τ; type=pval_type)
7175
end
7276

7377

@@ -109,9 +113,9 @@ function perm_clusterdepths_both(
109113
# inplace!
110114
statfun!(d0, d_perm)
111115
end
112-
if !isnothing(sidefun)
113-
d0 .= sidefun.(d0)
114-
end
116+
117+
d0 .= sidefun.(d0)
118+
115119
# get clusterdepth
116120
(fromTo, head, tail) = calc_clusterdepth(d0, τ)
117121

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ my_statfun = x->studentt_unpaired(x,grp)
9090
```
9191
9292
"""
93-
function studentt_unpaired(x::AbstractArray, group)
93+
function studentt_unpaired(x, group)
9494
x_reshaped = reshape(x, :, size(x, ndims(x)))
9595
x₁ = x_reshaped[:, group]
9696
x₂ = x_reshaped[:, .!group]

test/cluster.jl

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,52 @@
1616
)
1717
@test s == [3, 5]
1818
@test l == [0, 1]
19+
20+
s, l = ClusterDepth.cluster(
21+
[4.0, 0.0, 10.0, 0.0, 3.0, 4.0, 0, 4.0, 4.0] .> 0.9,
22+
)
1923
end
2024

2125
@testset "Tests for 2D data" begin
2226
data = randn(StableRNG(1), 4, 5)
23-
@show ClusterDepth.calc_clusterdepth(data, 0)
27+
res = ClusterDepth.clusterdepth(data; τ=0.4)
28+
@test size(res) == (4,)
2429
end
2530

2631
@testset "Tests for 3D data" begin
2732
data = randn(StableRNG(1), 3, 20, 5)
28-
@show ClusterDepth.clusterdepth(data; τ=0.4, nperm=5)
33+
res = ClusterDepth.clusterdepth(data; τ=0.4, nperm=5)
34+
@test size(res) == (3, 20)
2935
end
36+
@testset "Test sidefun" begin
37+
data = randn(StableRNG(1), 23, 20)
38+
data[3:8, :] .+= 3
39+
data[12:17, :] .-= 3
40+
res = ClusterDepth.clusterdepth(data; τ=0.4, nperm=5)
41+
res_negated = ClusterDepth.clusterdepth(.-data; τ=0.4, nperm=5)
42+
@test res res_negated # should be same if side_type=:abs
43+
44+
45+
# testing the default is abs
46+
res_abs = ClusterDepth.clusterdepth(data; τ=0.4, nperm=5, side_type=:abs)
47+
@test res res_abs
48+
49+
50+
res_pos = ClusterDepth.clusterdepth(data; τ=0.4, nperm=5, side_type=:positive)
51+
@test all(res_pos[3:8] .< 0.8)
52+
res_neg = ClusterDepth.clusterdepth(data; τ=0.4, nperm=5, side_type=:negative)
53+
@test all(res_neg[12:17] .< 0.8)
54+
55+
56+
end
57+
@testset "Test warning clusterbegin/end" begin
58+
59+
# test the warning that clusters must not begin/end with a potentially significant cluster
60+
data = randn(StableRNG(1), 23, 20)
61+
data[1:5, :] .+= 3
62+
@test_warn x -> occursin("Your data shows a cluster", x) Warning ClusterDepth.clusterdepth(data; τ=0.4, nperm=5)
63+
data = randn(StableRNG(1), 23, 20)
64+
data[23, :] .-= 3
65+
@test_warn x -> occursin("Your data shows a cluster", x) Warning ClusterDepth.clusterdepth(data; τ=0.4, nperm=5)
66+
67+
end

test/utils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ end
6767
x2 = _x[:, :, 2]
6868
x = hcat(x1, x2)
6969
group = repeat([false, true], inner=size(x1, 2))
70+
7071
t = ClusterDepth.studentt_unpaired(x, group)
7172

7273

74+
7375
t_true = [HypothesisTests.UnequalVarianceTTest(r[group], r[.!group]).t for r in eachrow(x)]
7476
@test all(t .≈ t_true)
7577
@test length(t) == 10000
@@ -81,5 +83,5 @@ end
8183
x = cat(x1, x2, dims=3)
8284
group = repeat([false, true], inner=size(x1, 3))
8385
t = ClusterDepth.studentt_unpaired(x, group .== 1)
84-
@test size(t) == (1000, 50)
86+
@test size(t) == (10000, 50)
8587
end

0 commit comments

Comments
 (0)