Skip to content

Commit

Permalink
Fix more deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jul 3, 2018
1 parent bf87a67 commit 3621446
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/Clustering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Clustering

using Printf
using LinearAlgebra
using SparseArrays
if VERSION >= v"0.7.0-beta.85"
using Statistics
end
Expand Down
2 changes: 1 addition & 1 deletion src/dbscan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function _dbscan(kdtree::KDTree, points::AbstractMatrix, radius::Real;
visited[current_index] && continue
visited[current_index] = true
append!(adj_list, inrange(kdtree, points[:, current_index], radius))
cluster_selection[adj_list] = true
cluster_selection[adj_list] .= true
# if a point doesn't have enough neighbors it is not a 'core' point and its neighbors are not added to the to_explore list
if (length(adj_list) - 1) < min_neighbors
empty!(adj_list)
Expand Down
2 changes: 1 addition & 1 deletion src/hclust.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ end
## update D(i,j) and N(i) accordingly
function hclust_minimum(ds::Symmetric{T}) where T<:Real
## For each i < j compute d[i,j] (this is already given)
d = full(ds) # we need a local copy
d = Matrix(ds) # we need a local copy
nc = size(d,1)
mr = Vector{Int}(undef, nc-1) # min row
mc = Vector{Int}(undef, nc-1) # min col
Expand Down
20 changes: 12 additions & 8 deletions src/mcl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ end
# `zero_tol` is a minimal value to consider as an element-to-cluster assignment
function _mcl_clusters(mcl_adj::AbstractMatrix, allow_singles::Bool, zero_tol::Float64 = 1E-20)
# remove rows containing only zero elements and convert into a mask of nonzero elements
el2clu_mask = mcl_adj[squeeze(sum(mcl_adj, dims=2), 2) .> zero_tol, :] .> zero_tol
el2clu_mask = mcl_adj[squeeze(sum(mcl_adj, dims=2), dims=2) .> zero_tol, :] .> zero_tol

# assign cluster indexes to each node
# cluster index is the index of the first TRUE in a given column
clu_ixs = squeeze(mapslices(el_mask -> !isempty(el_mask) ? findmax(el_mask)[2] : 0,
el2clu_mask, 1), 1)
@static if VERSION >= v"0.7.0-beta.73"
_ms = mapslices(el_mask->isempty(el_mask) ? 0 : argmax(el_mask), el2clu_mask, dims=1)
else
_ms = mapslices(el_mask->isempty(el_mask) ? 0 : argmax(el_mask), el2clu_mask, 1)
end
clu_ixs = squeeze(_ms, dims=1)
clu_sizes = zeros(Int, size(el2clu_mask, 1))
unassigned_count = 0
@inbounds for clu_ix in clu_ixs
Expand Down Expand Up @@ -151,8 +155,8 @@ function mcl(adj::AbstractMatrix{T};
# initialize the MCL adjacency matrix by normalized `adj` weights
mcl_adj = copy(adj)
# normalize in columns
scale!(mcl_adj, map(x -> x != 0.0 ? 1.0/x : x, squeeze(sum(mcl_adj, dims=1), 1)))
mcl_norm = vecnorm(mcl_adj)
rmul!(mcl_adj, Diagonal(map(x -> x != 0.0 ? 1.0/x : x, squeeze(sum(mcl_adj, dims=1), dims=1))))
mcl_norm = norm(mcl_adj)
if !isfinite(mcl_norm)
throw(OverflowError("The norm of the input adjacency matrix is not finite"))
end
Expand All @@ -171,10 +175,10 @@ function mcl(adj::AbstractMatrix{T};
_mcl_prune!(next_mcl_adj, prune_tol)

# normalize in columns
scale!(next_mcl_adj, map(x -> x != 0.0 ? 1.0/x : x,
squeeze(sum(next_mcl_adj, dims=1), 1)))
rmul!(next_mcl_adj, Diagonal(map(x -> x != 0.0 ? 1.0/x : x,
squeeze(sum(next_mcl_adj, dims=1), dims=1))))

next_mcl_norm = vecnorm(next_mcl_adj)
next_mcl_norm = norm(next_mcl_adj)
if !isfinite(next_mcl_norm)
@warn("MCL adjacency matrix norm is not finite")
break
Expand Down
4 changes: 2 additions & 2 deletions src/randindex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ function randindex(c1,c2)
c = counts(c1,c2,(1:maximum(c1),1:maximum(c2))) # form contingency matrix

n = round(Int,sum(c))
nis = sum(sum(c,2).^2) # sum of squares of sums of rows
njs = sum(sum(c,1).^2) # sum of squares of sums of columns
nis = sum(abs2, sum(c, dims=2)) # sum of squares of sums of rows
njs = sum(abs2, sum(c, dims=1)) # sum of squares of sums of columns

t1 = binomial(n,2) # total number of pairs of entities
t2 = sum(c.^2) # sum over rows & columnns of nij^2
Expand Down
6 changes: 4 additions & 2 deletions test/affprop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Test
using Distances
using Clustering
using LinearAlgebra
using Random

srand(34568)

Expand All @@ -12,7 +14,7 @@ x = rand(d, n)
S = -pairwise(Euclidean(), x, x)

# set diagonal value to median value
S = S - diagm(diag(S)) + median(S)*eye(size(S,1))
S = S - diagm(0 => diag(S)) + median(S)*I

R = affinityprop(S)

Expand All @@ -26,6 +28,6 @@ k = length(R.exemplars)
@test length(R.counts) == k
@test sum(R.counts) == n
for i = 1:k
@test R.counts[i] == countnz(R.assignments .== i)
@test R.counts[i] == count(==(i), R.assignments)
end

2 changes: 1 addition & 1 deletion test/dbscan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ k = length(R.seeds)
@test length(R.assignments) == n
@test length(R.counts) == k
for c = 1:k
@test countnz(R.assignments .== c) == R.counts[c]
@test count(==(c), R.assignments) == R.counts[c]
end
@test all(R.counts .>= 180)

Expand Down
2 changes: 1 addition & 1 deletion test/kmeans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ r2 = kmeans(x, k; maxiter=50, init=:kmcen)
@test sum(r.counts) == n
@test r.cweights == map(Float64, r.counts)
@test isapprox(sum(r.costs), r.totalcost)
for fn in fieldnames(r)
for fn in fieldnames(typeof(r))
@test getfield(r, fn) == getfield(r2, fn)
end
6 changes: 3 additions & 3 deletions test/mcl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ edges = Tuple{Symbol, Symbol, Float64}[(:cat, :hat, 0.2), (:hat, :bat, 0.16),
(:hit, :bit, 0.16)]
adj_matrix = zeros(Float64, length(nodes), length(nodes))
for edge in edges
n1 = findfirst(nodes, edge[1])
n2 = findfirst(nodes, edge[2])
n1 = findfirst(isequal(edge[1]), nodes)
n2 = findfirst(isequal(edge[2]), nodes)
adj_matrix[n1, n2] = adj_matrix[n2, n1] = edge[3]
end
@assert issymmetric(adj_matrix)
Expand All @@ -30,7 +30,7 @@ k = length(res.counts)
@test length(res.assignments) == length(nodes)
@test length(res.counts) == k
for c = 1:k
@test countnz(res.assignments .== c) == res.counts[c]
@test count(==(c), res.assignments) == res.counts[c]
end
@test res.nunassigned == 0
@test res.assignments == [1, 2, 1, 2, 1, 2]
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Clustering
using Test
using Random
using LinearAlgebra
using SparseArrays

tests = ["seeding",
"kmeans",
Expand Down

0 comments on commit 3621446

Please sign in to comment.