Skip to content

Commit ee88778

Browse files
author
Andrey Oskin
committed
Added benchmarks for new implementations
1 parent 2bfc81d commit ee88778

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

benchmark/bench01_distance.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ centroids = rand(10, 2)
1717
d = Vector{Float64}(undef, 100_000)
1818
suite["100kx10"] = @benchmarkable ParallelKMeans.colwise!($d, $X, $centroids)
1919

20-
# for reference
21-
metric = SqEuclidean()
22-
#suite["100kx10_distances"] = @benchmarkable Distances.colwise!($d, $metric, $X, $centroids)
23-
dist = Distances.pairwise(metric, X, centroids, dims = 2)
24-
min = minimum(dist, dims=2)
25-
suite["100kx10_distances"] = @benchmarkable $d = min
2620
end # module
2721

2822
BenchDistance.suite

benchmark/bench02_kmeans.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module BenchKMeans
2+
using Random
3+
using ParallelKMeans
4+
using BenchmarkTools
5+
6+
suite = BenchmarkGroup()
7+
8+
Random.seed!(2020)
9+
X = rand(10, 100_000)
10+
11+
centroids3 = ParallelKMeans.smart_init(X, 3, 1, init="kmeans++").centroids
12+
centroids10 = ParallelKMeans.smart_init(X, 10, 1, init="kmeans++").centroids
13+
14+
suite["10x100_000x3x1 Lloyd"] = @benchmarkable kmeans($X, 3, init = $centroids3, n_threads = 1, verbose = false, tol = 1e-6, max_iters = 1000)
15+
suite["10x100_000x3x1 Hammerly"] = @benchmarkable kmeans(Hamerly(), $X, 3, init = $centroids3, n_threads = 1, verbose = false, tol = 1e-6, max_iters = 1000)
16+
17+
suite["10x100_000x3x2 Lloyd"] = @benchmarkable kmeans($X, 3, init = $centroids3, n_threads = 2, verbose = false, tol = 1e-6, max_iters = 1000)
18+
suite["10x100_000x3x2 Hammerly"] = @benchmarkable kmeans(Hamerly(), $X, 3, init = $centroids3, n_threads = 2, verbose = false, tol = 1e-6, max_iters = 1000)
19+
20+
suite["10x100_000x10x1 Lloyd"] = @benchmarkable kmeans($X, 10, init = $centroids10, n_threads = 1, verbose = false, tol = 1e-6, max_iters = 1000)
21+
suite["10x100_000x10x1 Hammerly"] = @benchmarkable kmeans(Hamerly(), $X, 10, init = $centroids10, n_threads = 1, verbose = false, tol = 1e-6, max_iters = 1000)
22+
23+
suite["10x100_000x10x2 Lloyd"] = @benchmarkable kmeans($X, 10, init = $centroids10, n_threads = 2, verbose = false, tol = 1e-6, max_iters = 1000)
24+
suite["10x100_000x10x2 Hammerly"] = @benchmarkable kmeans(Hamerly(), $X, 10, init = $centroids10, n_threads = 2, verbose = false, tol = 1e-6, max_iters = 1000)
25+
26+
end # module
27+
28+
BenchKMeans.suite

src/hamerly.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ function chunk_update_bounds!(containers, r, r1, r2, pr1, pr2)
303303

304304
@inbounds for i in r
305305
label = labels[i]
306-
ub[i] += 2*sqrt(ub[i] * p[label]) + p[label]
306+
ub[i] += 2*sqrt(abs(ub[i] * p[label])) + p[label]
307307
if r1 == label
308-
lb[i] += pr2 - 2*sqrt(pr2*lb[i])
308+
lb[i] += pr2 - 2*sqrt(abs(pr2*lb[i]))
309309
else
310-
lb[i] += pr1 - 2*sqrt(pr1*lb[i])
310+
lb[i] += pr1 - 2*sqrt(abs(pr1*lb[i]))
311311
end
312312
end
313313
end

0 commit comments

Comments
 (0)