@@ -38,7 +38,7 @@ const _kmed_default_tol = 1.0e-8
38
38
const _kmed_default_display = :none
39
39
40
40
"""
41
- kmedoids(dist::DenseMatrix , k::Integer; ...) -> KmedoidsResult
41
+ kmedoids(dist::AbstractMatrix , k::Integer; ...) -> KmedoidsResult
42
42
43
43
Perform K-medoids clustering of ``n`` points into `k` clusters,
44
44
given the `dist` matrix (``n×n``, `dist[i, j]` is the distance
@@ -59,7 +59,7 @@ The function implements a *K-means style* algorithm instead of *PAM*
59
59
iterations, but was shown to produce worse (10-20% higher total costs) results
60
60
(see e.g. [Schubert & Rousseeuw (2019)](@ref kmedoid_refs)).
61
61
"""
62
- function kmedoids (dist:: DenseMatrix {T} , k:: Integer ;
62
+ function kmedoids (dist:: AbstractMatrix {T} , k:: Integer ;
63
63
init= _kmed_default_init,
64
64
maxiter:: Integer = _kmed_default_maxiter,
65
65
tol:: Real = _kmed_default_tol,
@@ -79,7 +79,7 @@ function kmedoids(dist::DenseMatrix{T}, k::Integer;
79
79
end
80
80
81
81
"""
82
- kmedoids!(dist::DenseMatrix , medoids::Vector{Int};
82
+ kmedoids!(dist::AbstractMatrix , medoids::Vector{Int};
83
83
[kwargs...]) -> KmedoidsResult
84
84
85
85
Update the current cluster `medoids` using the `dist` matrix.
@@ -89,7 +89,7 @@ as `medoids` argument.
89
89
90
90
See [`kmedoids`](@ref) for the description of optional `kwargs`.
91
91
"""
92
- function kmedoids! (dist:: DenseMatrix {T} , medoids:: Vector{Int} ;
92
+ function kmedoids! (dist:: AbstractMatrix {T} , medoids:: Vector{Int} ;
93
93
maxiter:: Integer = _kmed_default_maxiter,
94
94
tol:: Real = _kmed_default_tol,
95
95
display:: Symbol = _kmed_default_display) where T<: Real
110
110
# ### core algorithm
111
111
112
112
function _kmedoids! (medoids:: Vector{Int} , # initialized medoids
113
- dist:: DenseMatrix {T} , # distance matrix
113
+ dist:: AbstractMatrix {T} , # distance matrix
114
114
maxiter:: Int , # maximum number of iterations
115
115
tol:: Real , # tolerable change of objective
116
116
displevel:: Int ) where T<: Real # level of display
182
182
183
183
184
184
# update assignments and related quantities
185
- function _kmed_update_assignments! (dist:: DenseMatrix {T} , # in: (n, n)
185
+ function _kmed_update_assignments! (dist:: AbstractMatrix {T} , # in: (n, n)
186
186
medoids:: AbstractVector{Int} , # in: (k,)
187
187
assignments:: Vector{Int} , # out: (n,)
188
188
groups:: Vector{Vector{Int}} , # out: (k,)
233
233
# find medoid for a given group
234
234
#
235
235
# TODO : faster way without creating temporary arrays
236
- function _find_medoid (dist:: DenseMatrix , grp:: Vector{Int} )
236
+ function _find_medoid (dist:: AbstractMatrix , grp:: Vector{Int} )
237
237
@assert ! isempty (grp)
238
238
p = argmin (sum (dist[grp, grp], dims= 2 ))
239
239
return grp[p]:: Int
0 commit comments