简体   繁体   English

pvclust 的汉明距离度量

[英]Hamming distance measure for pvclust

I am trying to create a Hamming distance measure for the pvclust clustering method.我正在尝试为 pvclust 聚类方法创建汉明距离度量。 (There isn't one defined for this function.) I'm based on the example given for the cosine measure: (没有为这个 function 定义一个。)我基于为余弦度量给出的示例:

cosine <- function(x) {
x <- as.matrix(x)
y <- t(x) %*% x
res <- 1 - y / (sqrt(diag(y)) %*% t(sqrt(diag(y))))
res <- as.dist(res)
attr(res, "method") <- "cosine"
return(res)
}

I try to do it this way:我尝试这样做:

hamming <- function(x) {
x <- as.matrix(x)
y <- t(x) %*% x
res <- sum(y != y)
res <- as.dist(res)
attr(res, "method") <- "hamming"
return(res)
}

Unfortunately it doesn't work properly.不幸的是它不能正常工作。 Anyone have any postings, where is the error and how to fix it?任何人都有任何帖子,错误在哪里以及如何解决?

Try this尝试这个

hamming <- function(x) {
x <- as.matrix(x)
y <- (1 - x) %*% t(x)
res <- y + t(y)
res <- as.dist(res)
attr(res, "method") <- "hamming"
return(res)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM