【问题标题】:Hamming distance measure for pvclustpvclust 的汉明距离测量
【发布时间】:2022-06-15 00:33:09
【问题描述】:

我正在尝试为 pvclust 聚类方法创建汉明距离度量。 (没有为这个函数定义一个。)我基于为余弦测量给出的示例:

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)
}

我尝试这样做:

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)
}

不幸的是,它不能正常工作。谁有任何帖子,错误在哪里以及如何解决?

【问题讨论】:

  • 你遇到了什么错误?
  • 如果我尝试将此函数用于矩阵,我得到的值为 0。

标签: r pvclust


【解决方案1】:

试试这个

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

【讨论】:

    猜你喜欢
    • 2017-09-10
    • 1970-01-01
    • 2015-03-21
    • 2012-03-10
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    相关资源
    最近更新 更多