Skip to content

Commit fc57919

Browse files
committed
PR corrections
1 parent 563014a commit fc57919

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

doc/source/validate.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ mutualinfo
103103
## Confusion matrix
104104

105105
Pair [confusion matrix](https://en.wikipedia.org/wiki/Confusion_matrix)
106-
arising from two clusterings is a 2x2 contingency table representation of
107-
the partition co-occurrence table, see [`counts`](@ref).
106+
arising from two clusterings is a 2×2 contingency table representation of
107+
the partition co-occurrence, see [`counts`](@ref).
108108

109109
```@docs
110110
confusion

src/confusion.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
"""
2-
confusion(a::ClusteringResult, b::ClusteringResult) -> Matrix{Int}
3-
confusion(a::ClusteringResult, b::AbstractVector{<:Integer}) -> Matrix{Int}
4-
confusion(a::AbstractVector{<:Integer}, b::ClusteringResult) -> Matrix{Int}
5-
confusion(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer}) -> Matrix{Int}
2+
confusion(a::Union{ClusteringResult, AbstractVector},
3+
b::Union{ClusteringResult, AbstractVector}) -> Matrix{Int}
64
7-
Return 2x2 confusion matrix `C` that represents partition co-occurrence or
5+
Return 2×2 confusion matrix `C` that represents partition co-occurrence or
86
similarity matrix between two clusterings by considering all pairs of samples
97
and counting pairs that are assigned into the same or into different clusters
108
under the true and predicted clusterings.
119
1210
Considering a pair of samples that is in the same group as a **positive pair**,
1311
and a pair is in the different group as a **negative pair**, then the count of
14-
true positives is `C₀₀`, false negatives is `C₀₁`, false positives `C₁₀`, and
15-
true negatives is `C₁₁`:
12+
true positives is `C₁₁`, false negatives is `C₁₂`, false positives `C₂₁`, and
13+
true negatives is `C₂₂`:
1614
1715
| | Positive | Negative |
1816
|:--:|:-:|:-:|
19-
|Positive|C₀₀|C₁|
20-
|Negative|C₁|C₁₁|
17+
|Positive|C₁₁|C₁|
18+
|Negative|C₁|C₂₂|
2119
"""
2220
function confusion(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer})
2321
c = counts(a, b)
@@ -27,10 +25,11 @@ function confusion(a::AbstractVector{<:Integer}, b::AbstractVector{<:Integer})
2725
njs = sum(abs2, sum(c, dims=1)) # sum of squares of sums of columns
2826

2927
t2 = sum(abs2, c) # sum over rows & columns of nij^2
30-
t3 = nis+njs
31-
C = Int[(t2-n)/2 (nis-t2)/2; (njs-t2)/2 (t2+n^2-t3)/2]
28+
t3 = nis + njs
29+
C = [(t2 - n)÷2 (nis - t2)÷2; (njs - t2)÷2 (t2 + n^2 - t3)÷2]
3230
return C
3331
end
32+
3433
confusion(a::ClusteringResult, b::ClusteringResult) =
3534
confusion(assignments(a), assignments(b))
3635
confusion(a::AbstractVector{<:Integer}, b::ClusteringResult) =

src/randindex.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ Returns a tuple of indices:
1414
1515
# References
1616
> Lawrence Hubert and Phipps Arabie (1985). *Comparing partitions.*
17-
> Journal of Classification 2 (1): 193218
17+
> Journal of Classification 2 (1): 193-218
1818
1919
> Meila, Marina (2003). *Comparing Clusterings by the Variation of
20-
> Information.* Learning Theory and Kernel Machines: 173187.
20+
> Information.* Learning Theory and Kernel Machines: 173-187.
2121
22-
> Steinley, Douglas (2004). *Properties of the HubertArabie Adjusted
22+
> Steinley, Douglas (2004). *Properties of the Hubert-Arabie Adjusted
2323
> Rand Index.* Psychological Methods, Vol. 9, No. 3: 386-396
2424
"""
2525
function randindex(a, b)
26-
a, c, b, d = confusion(a,b) # Table 2 from Steinley 2004
26+
c11, c21, c12, c22 = confusion(a, b) # Table 2 from Steinley 2004
2727

28-
t = a+ b + c + d # total number of pairs of entities
29-
A = a + d
30-
D = b + c
28+
t = c11 + c12 + c21 + c22 # total number of pairs of entities
29+
A = c11 + c22
30+
D = c12 + c21
3131

3232
# expected index
33-
ERI = (a+b)*(a+c)+(c+d)*(b+d)
33+
ERI = (c11+c12)*(c11+c21)+(c21+c22)*(c12+c22)
3434
# adjusted Rand - Hubert & Arabie 1985
3535
ARI = D == 0 ? 1.0 : (t*A-ERI)/(t*t-ERI) # (9) from Steinley 2004
3636

0 commit comments

Comments
 (0)