Skip to content

Commit 1c2e0e6

Browse files
committed
bug fixes & verbose test
1 parent 10c7a95 commit 1c2e0e6

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ os:
55
- osx
66
julia:
77
- 1.3
8+
- 1.4
89
- nightly
910
after_success:
1011
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
@@ -14,7 +15,7 @@ jobs:
1415
fast_finish: true
1516
include:
1617
- stage: Documentation
17-
julia: 1.3
18+
julia: 1.4
1819
script: julia --project=docs -e '
1920
using Pkg;
2021
Pkg.develop(PackageSpec(path=pwd()));

docs/src/index.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ Taking advantage of Julia's brilliant multiple dispatch system, the package expo
5959
```julia
6060
using ParallelKMeans
6161

62-
# Use only 1 core of CPU
63-
results = kmeans(X, 3, ParallelKMeans.SingleThread(), tol=1e-6, max_iters=300)
64-
6562
# Use all available CPU cores
66-
multi_results = kmeans(X, 3, ParallelKMeans.MultiThread(), tol=1e-6, max_iters=300)
63+
multi_results = kmeans(X, 3; max_iters=300)
64+
65+
# Use only 1 core of CPU
66+
results = kmeans(X, 3; n_threads=1, max_iters=300)
6767
```
6868

6969
### Practical Usage Examples
@@ -80,7 +80,7 @@ iris = dataset("datasets", "iris");
8080
# features to use for clustering
8181
features = collect(Matrix(iris[:, 1:4])');
8282

83-
result = kmeans(features, 3, ParallelKMeans.MultiThread());
83+
result = kmeans(features, 3);
8484

8585
# plot with the point color mapped to the assigned cluster index
8686
scatter(iris.PetalLength, iris.PetalWidth, marker_z=result.assignments,
@@ -102,13 +102,12 @@ c = [ParallelKMeans.kmeans(X, i; tol=1e-6, max_iters=300, verbose=false).totalco
102102

103103
# Single Thread Implementation plus a modified version of Elkan's triangiulity of inequaltiy
104104
# to boost speed
105-
e = [ParallelKMeans.kmeans(ParallelKMeans.LightElkan(), X, i,
106-
n_threads=1, tol=1e-6, max_iters=300,
107-
verbose=false).totalcost for i = 2:10]
105+
e = [ParallelKMeans.kmeans(LightElkan(), X, i;
106+
n_threads=1, tol=1e-6, max_iters=300, verbose=false).totalcost for i = 2:10]
108107

109108
# Multi Thread Implementation plus a modified version of Elkan's triangiulity of inequaltiy
110109
# to boost speed
111-
d = [ParallelKMeans.kmeans(ParallelKMeans.LightElkan(), X, i;
110+
d = [ParallelKMeans.kmeans(LightElkan(), X, i;
112111
tol=1e-6, max_iters=300, verbose=false).totalcost for i = 2:10]
113112
```
114113

src/kmeans.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function kmeans!(alg, containers, design_matrix, k;
128128

129129
if verbose
130130
# Show progress and terminate if J stopped decreasing.
131-
println("Iteration $iter: Jclust = $J")
131+
@info("Iteration $niters: Jclust = $J")
132132
end
133133

134134
# Check for convergence
@@ -145,7 +145,7 @@ function kmeans!(alg, containers, design_matrix, k;
145145

146146
# Terminate algorithm with the assumption that K-means has converged
147147
if verbose & converged
148-
println("Successfully terminated with convergence.")
148+
@info("Successfully terminated with convergence.")
149149
end
150150

151151
# TODO empty placeholder vectors should be calculated

test/test05_verbose.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module TestVerbosity
2+
3+
using ParallelKMeans
4+
using Random
5+
using Test
6+
7+
8+
@testset "Testing verbosity of implementation" begin
9+
Random.seed!(2020)
10+
X = rand(4, 150)
11+
Random.seed!(2020)
12+
@test_logs (:info, "Iteration 1: Jclust = 0.31023197229652544") kmeans(X, 3, n_threads=1, max_iters=1)
13+
14+
end
15+
16+
end # module
17+

0 commit comments

Comments
 (0)