koheiw / proxyC

R package for large-scale similarity/distance computation
GNU General Public License v3.0
29 stars 6 forks source link

A bug in drop0 #16

Closed koheiw closed 3 years ago

koheiw commented 3 years ago

Giovanni Tricarico reported this strange behavior via email. 1 diagona is moved to wrong places.

require(Matrix)
#> Loading required package: Matrix

dfu <- data.frame(item = c(1,1,1,2,2,3,3,3,4,4,5,5,5), features = LETTERS[c(1,2,3,1,4,3,4,6,1,6,5,8,13)], 
                  stringsAsFactors = F)
m <- xtabs(~item+features,dfu,sparse=T)

proxyC::simil(m, method = "jaccard", drop0 = F)
#> 5 x 5 sparse Matrix of class "dsTMatrix"
#>      1         2    3         4 5
#> 1 1.00 0.2500000 0.20 0.2500000 0
#> 2 0.25 1.0000000 0.25 0.3333333 0
#> 3 0.20 0.2500000 1.00 0.2500000 0
#> 4 0.25 0.3333333 0.25 1.0000000 0
#> 5 0.00 0.0000000 0.00 0.0000000 1
proxyC::simil(m, method = "jaccard", drop0 = T)
#> 5 x 5 sparse Matrix of class "dsTMatrix"
#>      1         2    3         4 5
#> 1 1.00 0.2500000 0.20 0.2500000 1
#> 2 0.25 1.0000000 0.25 0.3333333 .
#> 3 0.20 0.2500000 1.00 0.2500000 .
#> 4 0.25 0.3333333 0.25 1.0000000 .
#> 5 1.00 .         .    .         .

Created on 2021-04-17 by the reprex package (v1.0.0)